salida de Java desde el texto utilizando el flujo de datos de entrada se lee de la interfaz de documentos escogió Verdadero o Falso

Después de enterarse de los flujos de entrada y de salida hizo un pequeño programa

Después de leer los datos para tomar una decisión GUI Verdadero o Falso

Por último, el botón final se ha cambiado, el fin último no ha cambiado un gran efecto

¡Ay! Así sea! !

Veremos!

com.Grap empaquetar;


java.awt.BorderLayout importación;
java.awt.Container importación;
java.awt.FlowLayout importación;
java.awt.GridLayout importación;
java.awt.event.ActionEvent importación;
java.awt.event.ActionListener importación;
java.awt.event.ItemEvent importación;
java.awt.event.ItemListener importación;
java.io.BufferedInputStream importación;
java.io.BufferedReader importación;
java.io.FileNotFoundException importación;
java.io.FileOutputStream importación;
java.io.FileReader importación;
java.io.IOException importación;


javax.swing.ButtonGroup importación;
javax.swing.JButton importación;
javax.swing.JFrame importación;
javax.swing.JLabel importación;
javax.swing.JPanel importación;
javax.swing.JRadioButton importación;
javax.swing.JScrollPane importación;
javax.swing.JTextArea importación;


public class javaIODemo extiende implementa ActionListener JFrame, ItemListener {
JPanel p1, p2, p3, p4;
JLabel jlQuestion, jlSelect, jlScore;
JButton botón Start, NextButton, StopButton;
Textarea JTextArea;
Panel de desplazamiento JScrollPane;
Botón JRadioButton [];
ButtonGroup ButtonGroup;
Br BufferedReader;
Respuesta de cuerda; void display () throws IOException { p1 = new JPanel (); P2 = new JPanel (); P3 = new JPanel (); p4 = new JPanel (); jlQuestion = new JLabel ( "题目"); jlSelect = new JLabel ( "选项"); jlScore = new JLabel ( ""); botón Start = new JButton ( "开始");








NextButton = new JButton ( "下一题");
StopButton = new JButton ( "结束");
textarea = nuevo JTextArea (3,30);
panel de desplazamiento = new JScrollPane (área de texto);
botón = nuevo JRadioButton [4];
ButtonGroup = new ButtonGroup ();
for (int i = 0; i <4; i ++) {
botón [i] = new JRadioButton ( "");
buttongroup.add (botón [i]);
botón [i] .addItemListener (this);
}
Br = new BufferedReader (nuevo FileReader ( "G: \\ text.txt"));
int m = 0;
br.mark (m);
Container c = getContentPane (); //上部添加
p3.add (jlQuestion);
p3.add (panel de desplazamiento);
c.add (p3, BorderLayout.NORTH); p1.setLayout (nuevo GridLayout (2,1)); //中心添加p1.add (p4); p1.add (jlScore); p4.add (jlSelect);




for (int i = 0; i <4; i ++) {
p4.add (botón [i]);
}
C.add (p1, BorderLayout.CENTER);
// p2.setLayout (nuevo FlowLayout ());
p2.add (botón Start); //下部添加
p2.add (NextButton);
p2.add (StopButton);
c.add (p2, BorderLayout.SOUTH);
setSize (400, 300);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
startbutton.addActionListener (this);
nextbutton.addActionListener (this);
stopbutton.addActionListener (this);
}
Pública showquestion vacío () throws Exception {
textarea.setText (br.readLine ());
for (int i = 0; i <4; i ++) {
botón [i] .setText (br.readLine ());
botón [i] .setEnabled (true);
}
Respuesta = br.readLine ();
jlScore.setText (" "); } @ Override public void itemStateChanged (ItemEvent e) { // generada-Auto TODO Stub for (int i = 0; i <4; i ++) { si (botón [i] .isSelected ()) si ((int) respuesta .charAt (0) == i + 65) jlScore.setText ( "恭喜你,答对了"); otra cosa jlScore.setText ( "答案错误!"); } } @Override public void actionPerformed (ActionEvent e) { // TODO Auto generados por el método talón de si (e.getSource () == || botón Start e.getSource () == NextButton) { try { showquestion (); } catch (e1 Excepción) { e1.printStackTrace (); } } Si (e.getSource () == StopButton) {





























startbutton.setEnabled (false);
nextbutton.setEnabled (false);
// for (int i = 0; i <4; i ++) {
// si (botón [i] .isSelected ())
// botón [i] .setSelected (false);
//// botón [i] .setEnabled (false);
// }
stopbutton.setOpaque (true);
stopbutton.addActionListener (this);
}
} Void main (String [] args) public static throws Exception { generada automáticamente // TODO Stub (nueva javaIODemo ()) pantalla (.); }






}








El último en hacerlo es el caso! !

Espero que no adopte! !


Se han publicado 19 artículos originales · ganado elogios 58 · Vistas a 50000 +

Supongo que te gusta

Origin blog.csdn.net/cyg_l02/article/details/80344891
Recomendado
Clasificación