0
您好我在創建一個actionlistener時會遇到一些麻煩,它會使用JRadioButtons作爲選擇創建一個新框架。使用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();
}
請大家幫忙,我不知道該怎麼辦 –