public class Main {
public static void main(String[] args) {
new guiTest().init();
}
}
class guiTest extends JFrame{
public void init(){
getContentPane().add(new MyPanel());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setSize(500,500);
setLocationRelativeTo(null);
setVisible(true);
}
}
class MyPanel extends JPanel{
public void paintComponent(Graphics graphic){
Graphics2D g = (Graphics2D) graphic;
g.setBackground(Color.red);
}
}
为什么这样设置不了背景色