我有非常简单的代码,只有2个按钮来显示textArea中数组的数字。
public class FotyUI extends javax.swing.JFrame {
public FotyUI() {
initComponents();
}
int[] numbers = {0,1,2,3,4,5,6,7,8,9};
int position = 0;
private void nextActionPerformed(java.awt.event.ActionEvent evt) {
position ++;
tekst.setText(" " + numbers[position]);
}
private void previousActionPerformed(java.awt.event.ActionEvent evt) {
position--;
tekst.setText(" " + numbers[position]);
}
现在,这段代码运行得很好我有两个按钮和textArea,但我想创建一个带有2个按钮的外部JFrame2来控制/显示第1帧的数组 当我输入:
public class FotyUI extends javax.swing.JFrame {
public FotyUI() {
initComponents();
}
int[] numbers = {0,1,2,3,4,5,6,7,8,9};
int position = 0;
JFrame temp = new JFrame();
JPanel panelik = new JPanel();
JButton nextS = new JButton("Next");
JButton prevS = new JButton("Previous");
panelik.add(nextS);
创建包panelik时出错... 你能帮我吗 ?如何使用2个按钮和textArea创建第2帧以显示/控制来自第1帧的数组内容
答案 0 :(得分:1)
JFrame frame = new JFrame("Test");
frame.setVisible(true);
frame.setSize(500,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
JButton button = new JButton("hello agin1");
panel.add(button);
pole = new JTextField();
panel.add(pole);
button.addActionListener (new Action1());
static class Action1 implements ActionListener {
public void actionPerformed (ActionEvent e) {
position ++;
tekst.setText(" " + numbers[position]);
pole.setText(" " + numbers[position]);
}
}