|
A great doubt in Java Applet,will u solve it!!
I have created an applet where I have created 3 buttons for the following actions:
1.A drawn line should appear! After clicking each button which is at different coordination.
BUT ONLY THE APPLET STARTS BUT NOTHING IS DISPLAYED!!,ONLY BLANK WINDOW.
Please just RUN THE SOURCE CODE which I have tried out!! So that you get a clear idea of my problem
MY PROGRAM:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyButton extends JApplet implements ActionListener
{
int i;
JButton one,two,three;
Container con;
public void init()
{
one=new JButton("one");
two=new JButton("two");
three=new JButton("three");
con=getContentPane();
con.setLayout(new FlowLayout());
con.add(one);
con.add(two);
con.add(three);
one.addActionListener(this);
two.addActionListener(this);
three.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==one)
{
i=1;
repaint();
}
else
if (e.getSource()==two)
{
i=2;
repaint();
}
if (e.getSource()==three)
{
i=3;
repaint();
}
}
public void paint(Graphics g)
{
if(i==1){
g.drawLine(180,40,20,100);
}
else if(i==2)
{
g.drawLine(140,20,30,100);
}
if(i==3)
{
g.drawLine(120,25,20,100);
}
}
/*<APPLET CODE="MyButton.class" HEIGHT=200 WIDTH=200>
</APPLET>
*/
}
IF YOU FOUND ANY BUG IN THIS PROGRAM,PLEASE EDIT IT!!
THANKS!!!
|