基本上,目前我正在执行ArrayList
中的某些操作,当我点击Play
按钮时,它们会输出到TextArea
。我还有另外两个按钮,Start
和Stop
。
我的硬盘有点工作,但我似乎无法实现启动和停止按钮。我将附上我的部分代码,以便您能够看到。提前致谢!!
public class jPanelBottom extends javax.swing.JPanel
{
private JTextField jtfBoundaryLength, jtfArea;
private JSlider jsShapes;
private JLabel jLabelBoundaryLength, jLabelArea, jLabelSlider;
private JButton jbStart, jbStop, jbPlay;
public static ActionPanel yes;
public jPanelBottom()
{
initComponents();
jbStart = new JButton();
jbStop.setText("Start");
jbStart.setSize(80, 25);
jbStart.setLocation(400, 95);
this.add(jbStart);
jbStop = new JButton();
jbStop.setText("Stop");
jbStop.setSize(80, 25);
jbStop.setLocation(500, 95);
this.add(jbStop);
jbPlay = new JButton();
jbPlay.setText("Play");
jbPlay.setSize(80, 25);
jbPlay.setLocation(600, 95);
this.add(jbPlay);
jbPlay.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
try{
//jbStart.addActionListener(this);
{
jbPlay.addActionListener(this);
ArrayList<String> list = MyFrame.shape1.getArrayList();
for (String s : list)
{
ActionPanel.jtaWoof.append(s);
ActionPanel.jtaWoof.append("\n");
}
}}catch(Throwable ex){}}
});
}
我真的很感激任何帮助!
答案 0 :(得分:0)
最好的方法是添加一般的actionPerformed:
public class Frame extends JFrame implements ActionListener{
[...]
public Frame(){
JButton Test = new JButton("Nutton Name");
[...]
Test.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e){
Object src = e.getSource();
if(src == Test){
System.out.print("You've pressed Test!");
}
}
}
不要忘记添加.addActionListener并将ActionListener实现到该类。 这比每次添加一个容易得多。