女士们,先生们,您好,我再次无法弄清楚对您来说可能很简单的事情。我正在尝试加载 3 个图像 space.jpeg、treefrog.jpeg 和 yosemite.jpeg(当您单击显示相应图像的单选按钮时)并尝试调整我能找到的每个示例。如果有人想指出我正确的方向,我将不胜感激。
package guiprogramming;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
public class ChooseImage extends JPanel {
private JPanel panel1;
private SimplePanel drawingPanel;
JRadioButton button1, button2, button3;
public ChooseImage() {
setLayout(new BorderLayout());
panel1 = new JPanel();
drawingPanel = new SimplePanel();
button1 = new JRadioButton("Scenery");
panel1.add(button1);
button2 = new JRadioButton("Space");
panel1.add(button2);
button3 = new JRadioButton("Tree Frog");
panel1.add(button3);
ButtonGroup group = new ButtonGroup();
group.add(button1);
group.add(button2);
group.add(button2);
this.add(panel1, BorderLayout.NORTH);
this.add(drawingPanel, BorderLayout.CENTER);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//This is where I am trying to get the images to load
}});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//This is where I am trying to get the images to load
}});
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//This is where I am trying to get the images to load
}});
}
public static void main(String[] args) {
JFrame window = new JFrame("Choose Image");
ChooseImage panel = new ChooseImage();
window.setContentPane(panel);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(500, 500);
window.setVisible(true);
}
}