import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
public class Draw_sj extends JApplet implements ActionListener{
private JButton jb1,jb2;
private int what;
int plX[]={40,40,160,40};
int plY[]={40,120,40,40};
int pl=3;
JLabel label;
public static final int Polygon=1;
public Draw_sj() {
}
public void init(){
jb1=new JButton("三角");
JPanel jp=new JPanel();
jp.add(jb1);
this.getContentPane().add(jp,BorderLayout.SOUTH);
jb1.addActionListener(this);
label=new JLabel();
add(label);
}
public void paint(Graphics g){
g.drawString("it is a button",20,30);
super.paint(g);
switch(what){
case Polygon:
g.drawPolygon(plX,plY,pl);
break;
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jb1){
what=Polygon;
repaint();
}
}
}
大家好~我新人~刚刚来的~
我想搞个程序 一按 按钮 显示三角 还可以 显示三角的信息~~!
可是显示三角的信息不会做~
请达人帮忙~~!