好的,这可能是一个愚蠢的问题,但总的来说我是 GUI 和 Java 的新手。在我的 GUI 中,我制作了我的框架,因为我在哪里看不到 JFrame。还是我必须创建一个 JFrame 并将我拥有的所有东西都放在上面。我需要一个 JFrame 来执行最小化屏幕、更改图标等操作。感谢您的帮助!
private ImageIcon bgi;
private JLabel bgl;
private JButton startButton;
private JButton helpButton;
private JButton backButton;
private final Action action = new SwingAction();
public static void main(String[] args) throws MalformedURLException, IOException {
TwitterUnfollower gui = new TwitterUnfollower ();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // when click x close program
gui.setSize(902, 305);
gui.setVisible(true);
gui.setTitle("Solid Cloud Inc - Twitter Unfolower");
}
public TwitterUnfollower() throws MalformedURLException, IOException{
bgi = new ImageIcon(getClass().getResource("tu.png"));
getContentPane().setLayout(null);
BufferedImage img = ImageIO.read(new URL("http://i1344.photobucket.com/albums/p656/SolidCloudInc/start_zpsf3781681.png"));
//ImageIcon start = new ImageIcon(getClass().getResource("start.png"));
startButton = new JButton("");
startButton.setIcon(new ImageIcon(img));
startButton.setBounds(22, 186, 114, 50);
getContentPane().add(startButton);
BufferedImage img2 = ImageIO.read(new URL("http://i1344.photobucket.com/albums/p656/SolidCloudInc/help_zpsc4fad867.png"));
helpButton = new JButton("");
helpButton.setIcon(new ImageIcon(img2));
helpButton.setBounds(192, 186, 114, 50);
getContentPane().add(helpButton);
BufferedImage img3 = ImageIO.read(new URL("http://i1344.photobucket.com/albums/p656/SolidCloudInc/back_zps9d62b65b.png"));
backButton = new JButton("");
backButton.setIcon(new ImageIcon(img3));
backButton.setBounds(105, 205, 82, 44);
backButton.setBorder(BorderFactory.createEmptyBorder());
backButton.setContentAreaFilled(false);
backButton.setVisible(false);
getContentPane().add(backButton);
bgl = new JLabel (bgi);
bgl.setBounds(0, 0, 886, 272);
getContentPane().add(bgl);
Events e = new Events();
startButton.addActionListener(e);
helpButton.addActionListener(e);
backButton.addActionListener(e);
}
}
我确实有一个动作监听器,我从代码中删除了它以使其更短。而且我知道我应该避免空布局,但我使用的是 WindowBuilder,这可能会改变。再次感谢!