|
Hy guys ! i'm running into a bit of trouble with a JScrollPane, the pane itself has to stay the same size but the viewport inside the pane has to get longer as i add stuff to it( right now i'm just drawing circles downwards)
the problem is that when the viewport gets big enough to require scrolling my drawing dissapears
my globals :
public int positionY=10;
public int positionX=20;
public int width=30;
public int height=30;
private Dimension dim=new Dimension();
private MyJViewport drawHere=new MyJViewport();
private JScrollPane displayResult;
private JButton jButton1;
the MyJViewport class :
class MyJViewport extends JViewport {
@Override
public void paint(Graphics g) {
g.setColor(Color.BLUE);
g.fillOval(positionX, positionY, width, height);
}
}
in the constructor i instance the scrollpane :
displayResult = new javax.swing.JScrollPane(drawHere);
displayResult.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
displayResult.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
the event handler for the button press:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
positionY+=height;
if (positionY > drawHere.getHeight()) {
dim.height = drawHere.getHeight() + height;
dim.width = drawHere.getWidth();
drawHere.setPreferredSize(dim);
drawHere.revalidate();
}
drawHere.repaint();
}
can anyone help with this ?
|
|
|
|
|
It looks like you are only painting the last item.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I don't understand , do you mean the last item in the scrollpane ? there is only the viewport in there, can you please explain ?
|
|
|
|
|
All your code is doing is painting a circle at the LAST position. The repaint needs to paint EVERY circle.
The simplest approach is to have a collection of objects each representing on of the thing you wish to display.
Each class knows how and where to piant itself on a given graphic:
[this code is not tested]
class MyCircle
{
private int top;
private int left;
private int radius;
MyCircle (int top, int left, int radius)
{
this.top = top;
this.left = left;
this.radius = radius;
}
void Repaint (Graphic g)
{
g.setColor(Color.BLUE);
g.fillOval(this.top,
this.left,
this.radius,
this.radius);
}
}
As you add your curcles create a new object with the X,Y,R. Hold these in a list object.
On the scrollpane repant iterate through the list and paint each object.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I see now thank you for explaining !
|
|
|
|
|
this is related to hacking a website via mobile. A user is able to hack a website using mobile phones. different mobiles are configured with different browsers. but the website when developed is error free and cannot be hacked if used with different versions of IE and mozila. Since the mobile applications are enabled with java script so by changing the different mode the hackers are accesing the website. So how to check it and what are the different features of testing it.
|
|
|
|
|
raghvendrapanda wrote: hacking a website via mobile
raghvendrapanda wrote: hack a website
raghvendrapanda wrote: hackers are accesing the website
I don't think Chris or the Hamsters will be too pleased about this question. If you want to perform nefareous deads don't admit it here. If you want to perform legitimate operations try using some better words.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
How to extract only the public key from any digital certificate???
I am writing an email client which sends encrypted emails in java....
|
|
|
|
|
Hi All,
I need an insight on how Java handles events like basic click events.
I know how it is done but, just wanted to know the process in detail, like what class hierarchy is followed while handling events. How the event classes like ActionEvent get the information about the source, how the event occurence is multicasted among different registered event listeners.
I tried to find this detail in books but wasn't successful and invested good amount of time for it.
Your help is welcome with thanks.
|
|
|
|
|
Zealous_Me wrote: I tried to find this detail in books but wasn't successful and invested good amount of time for it.
Did you ask Dr Intarweb?
A quick google for 'ActionEvent javadoc' found this[^] in the first reply.
Every, and I do mean EVERY, class in java has a javadoc. Maybe you haven't generated all your own, but ALL the shipped API objects have a javadoc ready and waiting. It is your friend and will tell you what you want to know. javadoc likes being asked questions.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi, I tried with javadoc also and I do have all the APIs and their documentation. But, still the mechanism isn't described anywhere. Probing into every API and finding out its connection with every other interface and class directly or indirectly associated is a very long and time taking business.
Thats why I tried to sought an answer on this forum.
Nevertheless your response is still welcome.
Thank you.
|
|
|
|
|
plz any body tell me how i write this expression in java'
C and B are int type of arrayand X is polynomial
X(i)<-X(i)+B().X(N-m is power of X)
|
|
|
|
|
You don't just need help, you need leasons.
0 - No cross posting.
1 - Title refers to problem.
2 - The use of txtspk is strictly prohibited.
3 - Give code examples to show you actually tried something, or
4 - explain the concept you are trying to achieve.
You score null.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hy guys ! i'm trying to make an array with the components of my applet like this :
instancing :
public Component[] componente=new Component[100];
@Override
public void init() {
try {
componente=this.getComponents();
...
}
and displaying in a textArea :
for (int i=0;i<componente.length;i++)
{
status.setText("componente :\n");
status.append(i+" "+componente[i].getName()+"\n");
}
the result i get is :
componente :
0 null
my applet however has plenty of componenets, does anybody know why this might happen ?
|
|
|
|
|
The reason it returns null is because the componants havent been initialized by the time init() is called.
Solution: Don't call componente=this.getComponents(); from within init.
Have a look at this[^] for an explanation.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
I suspected that was it, i made my gui using netbeans IDE and it generates an initComponents method , and even tho i used getComponents inside this method afetr it instances the componenets i still get null
|
|
|
|
|
I presume you have something like this:
public GUIView(SingleFrameApplication app) {
super(app);
initComponents();
//TRY IT HERE
}
Personally I hate NetBeans and normally write it all by hand.
This is for a JFrame Application, apologies.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
modified on Saturday, May 9, 2009 12:29 PM
|
|
|
|
|
i really don't have a choice aside from working with netbeans sice my deadline is close and it could never be done in time if i learned how to do it by hand
the call is like this :
public void init() {
try {
initComponents();
initMyComponents();
} catch (Exception ex) {
ex.printStackTrace();
}
}
is there any other way to tell when the initialization is over, or when initComponenets is done executing?
|
|
|
|
|
Try this:
@Override
public void start()
{
}
I haven't used Applets in years, I'm a bit rusty.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
tried that , even inside the paint method , nothing works
btw thanks for all your time fly904
|
|
|
|
|
i am doing a project which is students‘Experiment management system.
then one function of it is teachers' modify students' experiment report.
so i need to add a online word editor to my project.
i hava tried to use dosframer and javascript.but the activex is only available in ie6.so it brings me a lot of trouble!
who can help me and give me some useful suggestions?oh ,my project is based on j2ee. also ,you can visit my website to give me some good suggestions.
if you visit my website ,the userid is 02910 password is 8764321 .you have to choose the category and the category is 教师.then you can try to test it!
the website is http://kforce.vicp.net:1013/ProjectX/[^]
thank you !
modified on Saturday, May 9, 2009 3:58 AM
|
|
|
|
|
0) Don' hand out your username and password, that's not a clever thing to do.
1) Your site is all in chinese(???), not many people here speak or read chinese so this is less than helpful.
2) Be more specific, just say you want to edit a Word file (*.doc) on a web page.
The only two useful bits in your post were:
qiuxumin1 wrote: so i need to add a online word editor to my project.
and
qiuxumin1 wrote: i hava tried to use dosframer and javascript.but the activex is only available in ie6.
The rest is unessesary and irrelevant.
3) Have a look at this[^].
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
thank you very much!
yes,i am from china!i will improve my english!
i hope i can keep in touch with you and learn java from you !
i know using dosframer will lower its security but i hava no other ways!
|
|
|
|
|
Hy guys ! i've been using netbeans to make a GUI, and i'm having rpoblems figuring out how to draw stuff using the canvas object, i've created a canvas object but it needs a graphics object in order to draw stuff, and that's where my problems start, for the life of me i can not understand how to use one of these
this is what i've tried so far :
Graphics g=null;
g.setColor(new Color(255,0,0));
canvas1.paint(g);
when i run this java flares up with null pointer exceptions altho the canvas itself has been instantiated
i've looked on the sun homepage for guidance but there is no hint on how to use an instance of a canvas object, they way they show is by creating a class that inherits Canvas and overwriting it's paint method, but that's no use to me
|
|
|
|
|
I'm not a professional Java programmer, but
g=null; immediately followed by
g.setColor(... doesn't quite look right.
I'd follow the advice of Sun's documentation. Generally the people who made the language know how it's supposed to be used. I found lots of information with a simple google search of "Java Graphics class".
|
|
|
|