H
hua song
i just learn java
write a applet..
but it can't show what i want...
can anyone help me?
import java.awt.*;
import javax.swing.*;
import java.awt.Event.*;
public class Jj extends JApplet{
public static int a;
public static int b;
public void init()
{
a=Integer.parseInt(getParameter("Value1"));
b=Integer.parseInt(getParameter("Value2"));
Container cp=getContentPane();
Buttonlistener bl=new Buttonlistener();
cp.add(bl);
show();
}
public class FillPanel2 extends JPanel{
private int aa;
private int bb;
FillPanel2(int aa,int bb)
{
this.aa=aa;
this.bb=bb;
}
public void paintComponment(Graphics g)
{
super.paintComponent(g);
g.drawOval(aa,bb,80,30);
}
}
public class FillPanel1 extends JPanel{
private int aa;
private int bb;
FillPanel1(int aa,int bb)
{
this.aa=aa;
this.bb=bb;
}
public void paintComponment(Graphics g)
{
super.paint(g);
g.drawRect(aa,bb,80,30);
}
}
public class Buttonlistener extends JPanel implements ActionListener{
public void ButtonListener(){//æž„é€ å‡½æ•°
Button b1=new Button("rect");
Button b2=new Button("oval");
Button b3=new Button("round");
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String s=((Button)e.getSource()).getLabel() ;
if(s.equals("rect"))
{
FillPanel1 fp =new FillPanel1(Jj.a,Jj.b);
add(fp);
}
if(s.equals("oval"))
{
FillPanel2 fp=new FillPanel2(Jj.a,Jj.b );
add(fp);
}
if(s.equals("round"))
{
FillPanel3 fp=new FillPanel3(Jj.a,Jj.b );
add(fp);
}
}
}
public class FillPanel3 extends JPanel{
private int aa;
private int bb;
public FillPanel3(int a, int b) {
aa=a;
bb=b;
}
public void paintComponent(Graphics g)
{
super.paint(g);
g.drawOval( aa,bb,50,50);
}
}
}
write a applet..
but it can't show what i want...
can anyone help me?
import java.awt.*;
import javax.swing.*;
import java.awt.Event.*;
public class Jj extends JApplet{
public static int a;
public static int b;
public void init()
{
a=Integer.parseInt(getParameter("Value1"));
b=Integer.parseInt(getParameter("Value2"));
Container cp=getContentPane();
Buttonlistener bl=new Buttonlistener();
cp.add(bl);
show();
}
public class FillPanel2 extends JPanel{
private int aa;
private int bb;
FillPanel2(int aa,int bb)
{
this.aa=aa;
this.bb=bb;
}
public void paintComponment(Graphics g)
{
super.paintComponent(g);
g.drawOval(aa,bb,80,30);
}
}
public class FillPanel1 extends JPanel{
private int aa;
private int bb;
FillPanel1(int aa,int bb)
{
this.aa=aa;
this.bb=bb;
}
public void paintComponment(Graphics g)
{
super.paint(g);
g.drawRect(aa,bb,80,30);
}
}
public class Buttonlistener extends JPanel implements ActionListener{
public void ButtonListener(){//æž„é€ å‡½æ•°
Button b1=new Button("rect");
Button b2=new Button("oval");
Button b3=new Button("round");
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String s=((Button)e.getSource()).getLabel() ;
if(s.equals("rect"))
{
FillPanel1 fp =new FillPanel1(Jj.a,Jj.b);
add(fp);
}
if(s.equals("oval"))
{
FillPanel2 fp=new FillPanel2(Jj.a,Jj.b );
add(fp);
}
if(s.equals("round"))
{
FillPanel3 fp=new FillPanel3(Jj.a,Jj.b );
add(fp);
}
}
}
public class FillPanel3 extends JPanel{
private int aa;
private int bb;
public FillPanel3(int a, int b) {
aa=a;
bb=b;
}
public void paintComponent(Graphics g)
{
super.paint(g);
g.drawOval( aa,bb,50,50);
}
}
}