我需要帮助使我尝试绘制的内容在屏幕上可见。我基本上能够正确设置它,但是我觉得将所有内容都放在自己的班级中会更有条理。窗口会出现,但不会画任何东西。甚至我设置的背景也没有出现。
public class CharacterCreator extends JPanel {
//Declare Variables
ImageIcon icon = new ImageIcon();
//PAINT
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
//Drawing Code
g.setColor(Color.red);
g.drawOval(10, 10, 10, 10);
}
//Window Creator
public CharacterCreator() {
super();
JFrame application = new JFrame();
application.setTitle("Window");
application.setBackground(Color.WHITE);
application.setIconImage(null);
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setSize(500, 400);
application.setLocationRelativeTo(null);
application.setVisible(true);
}
}
这是主要的样子:
public class GameProject {
public static void main(String [] args){
JPanel CC = new CharacterCreator();
}
}