举个简单的例子//<applet code = Paint.class width=600 height=400>//</applet>import javax.swing.*;import java.applet.*;import java.awt.*;public class Paint extends Applet {public void init(){JButton b1 = new JButton("开始");this.setLayout(null);b1.setBounds(100,100,80,40);this.add(b1);}public void paint(Graphics g){g.drawString("12345",100,120);}}
1 回答
白板的微信
TA贡献1883条经验 获得超3个赞
呵呵,重绘按钮就是了啊:
import javax.swing.*;
import java.applet.*;
import java.awt.*;
public class Paint extends Applet {
JPanel pnl=new JPanel();
JButton b1 = new JButton("开始");
public void init()
{
//b1.setBounds(100,100,80,40);
b1.setPreferredSize(new Dimension(100,50));
b1.setVisible(true);
//this.setLayout(null);
pnl.add(b1);
this.add(pnl);
this.setSize(300,200);
this.setVisible(true);
this.setLocation(400, 350);
//this.repaint();
}
public void paint(Graphics g)
{
g.drawString("跟我加高分哦",120,120);
pnl.repaint();
}
}
添加回答
举报
0/150
提交
取消