嗨,我在创建一个 actionlistener 时遇到了一些麻烦,该 actionlistener 创建了一个使用 JRadioButtons 作为选择的新框架。
最终,这将是一个我为好玩而创建的抽认卡测验程序。
这就是我卡住的地方:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FlashCard extends JFrame {
private ImageIcon myIcon = new ImageIcon("src/Resources/DNA.png");
public FlashCard(){
//Consider using CardLayout format for flashcards.
setLayout(new GridLayout(1, 4, 5, 5));
JButton startButton = new JButton("Begin");
add(startButton);
startButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
//Execute when button is pressed THIS IS THE PART WHERE I AM STUCK
JFrame frameAction = new JFrame();
frameAction.setTitle("Questions");
frameAction.setSize(350, 150);
frameAction.setLocationRelativeTo(null);
frameAction.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameAction.setVisible(true);
frameAction.
// JRadioButton jrb1 = new JRadioButton("Student", true);
// jrb1.setForeground(Color.RED);
// jrb1.setBackground(Color.WHITE);
// jrb1.setMnemonic('S');
//
// ButtonGroup group = new ButtonGroup();
// add(jrb1);
}
});
}
这是我的主要方法:
public static void main(String[] args){
//Create a frame and set its properties.
JFrame frame = new FlashCard();
frame.setTitle("Genetics FlashCard Quiz");
frame.setSize(350,150);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
//Create a second frame for when the user
// clicks begin.
JFrame question = new JFrame();
}