Why doesn't the JButton
appear?
package expt;
import java.awt.Graphics;
import javax.swing.*;
class th extends JFrame
{
JButton b=new JButton("Click");
th()
{
setVisible(true);
setSize(800, 400);
setResizable(false);
setDefaultCloseOperation(this.EXIT_ON_CLOSE);
setLayout(null);
getContentPane().add(b);
}
public void paint(Graphics g)
{
g.drawString("welcome", 150, 50);
}
public static void main(String args[])
{
new th();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…