【发布时间】:2016-03-10 00:20:14
【问题描述】:
我想检测单击JButton 时选择了哪些JComboBox 项目。结果将放在我在执行的操作中堆积的TextField 中。
例如,当我选择一个合适的数字时,它将使用 JButton 分类,结果将显示在 TextField 上。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class mFrame extends JFrame implements ActionListener
{
JLabel lblAge = new JLabel("Age");
JComboBox cboAge = new JComboBox();
JButton btnClass = new JButton("Classification");
JTextField txtField = new JTextField();
JButton btnClose = new JButton("Close");
public mFrame()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setSize(400,200);
add(lblAge);
add(cboAge);
add(btnClass);
add(txtField);
add(btnClose);
lblAge.setBounds(10,10,100,20);
cboAge.setBounds(140,10,120,20);
btnClass.setBounds(10,30,120,20);
txtField.setBounds(140,30,120,20);
btnClose.setBounds(200,105,70,20);
for (int j = 10; j < 101; j++) cboAge.addItem(new Integer(j));
cboAge.addActionListener(this);
btnClass.addActionListener(this);
txtField.addActionListener(this);
btnClose.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent age)
{
//if (age.getSource() == btnClass)
{
//
if (age.getSource() == btnClose)
{
System.exit(0);
}
}
}
}
class StartHere
{
public static void main(String [] args)
{
new mFrame();
}
}
【问题讨论】:
-
不能编辑我不知道为什么
-
完成编辑请检查