代码如下:
JFrame mainFrame = new JFrame();
JPanel panel = new JPanel();
mainFrame.setSize(width, height);
mainFrame.setLocationRelativeTo(null);
mainFrame.setResizable(false);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.getContentPane().setBackground(Color.WHITE);
mainFrame.getContentPane().setForeground(Color.WHITE);
mainFrame.setBackground(Color.WHITE);
mainFrame.add(panel);
mainFrame.setVisible(true);
Graphics g = panel.getGraphics();
运行的时候有时候背景会变成透明的,怎么解决? |
|