如下内容,能帮我改一下吗?想让控件和“12345”同时显示出来,不要在paint()中绘制控件?

举个简单的例子
//<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);
}
}

慕姐8265434
浏览 90回答 1
1回答

白板的微信

呵呵,重绘按钮就是了啊: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();}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java