Eclipse JSwing 计算器
Eclipse JSwing Calculator
我正在尝试使用 JSwing api 制作一个计算器。我完成了大约一半,得到了计算器,因此它的大部分功能都可以使用,但是当我在后面运行编写一些代码以使其更整洁并向计算器添加一些新选项时,但我运行 变成一个问题。当我运行它的时候,计算器的格式全错了,但是没有编辑源码。当我尝试使用 GUI 更改它时,window 生成器吐出一个错误。
这是我正在使用的代码:
package calculators;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.FlowLayout;
import net.miginfocom.swing.MigLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Component;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.JDesktopPane;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import javax.swing.JSeparator;
import java.awt.Color;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.border.TitledBorder;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import java.awt.Font;
private JPanel contentPane;
private JTextField textField;
JButton button0;
JButton button1;
JButton button2;
JButton button3;
JButton button4;
JButton button5;
JButton button6;
JButton button7;
JButton button8;
JButton button9;
JButton addNumbers;
JButton subNumbers;
JButton multNumbers;
JButton divNumbers;
JButton equalTo;
JButton clearAll;
JCheckBox integerMode;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LiLCalculator frame = new LiLCalculator();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LiLCalculator() {
setTitle("Lil Calculator");
JSeparator separator = new JSeparator();
separator.setOrientation(SwingConstants.VERTICAL);
separator.setForeground(Color.BLACK);
separator.setVisible(false);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "Precision", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel.setVisible(false);
JButton okButton = new JButton("<<<<OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 470, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
textField = new JTextField();
textField.setEditable(false);
textField.setHorizontalAlignment(SwingConstants.RIGHT);
textField.setText("0");
textField.setColumns(10);
JLabel label = new JLabel("");
button1 = new JButton("1");
button1.setFont(new Font("Tahoma", Font.PLAIN, 9));
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("1");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "1");
}
});
button2 = new JButton("2");
button2.setFont(new Font("Tahoma", Font.PLAIN, 9));
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("2");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "2");
}
});
button4 = new JButton("4");
button4.setFont(new Font("Tahoma", Font.PLAIN, 9));
button4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("4");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "4");
}
});
button5 = new JButton("5");
button5.setFont(new Font("Tahoma", Font.PLAIN, 9));
button5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("5");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "5");
}
});
button3 = new JButton("3");
button3.setFont(new Font("Tahoma", Font.PLAIN, 9));
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("3");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "3");
}
});
button6 = new JButton("6");
button6.setFont(new Font("Tahoma", Font.PLAIN, 9));
button6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("6");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "6");
}
});
button7 = new JButton("7");
button7.setFont(new Font("Tahoma", Font.PLAIN, 9));
button7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("7");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "7");
}
});
button8 = new JButton("8");
button8.setFont(new Font("Tahoma", Font.PLAIN, 9));
button8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("8");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "8");
}
});
button9 = new JButton("9");
button9.setFont(new Font("Tahoma", Font.PLAIN, 9));
button9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("9");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "9");
}
});
button0 = new JButton("0");
button0.setFont(new Font("Tahoma", Font.PLAIN, 9));
button0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("0");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "0");
}
});
subNumbers = new JButton("-");
subNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
LiLCalculations.setFirstDigit(true);
LiLCalculations.setCalcSelect(2);
LiLCalculations.setFirstNumber(x);
}
});
divNumbers = new JButton("/");
divNumbers.setFont(new Font("Tahoma", Font.PLAIN, 9));
divNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
button0.setEnabled(false);
LiLCalculations.setFirstDigit(true);
LiLCalculations.setCalcSelect(4);
LiLCalculations.setFirstNumber(x);
}
});
addNumbers = new JButton("+");
addNumbers.setFont(new Font("Tahoma", Font.PLAIN, 8));
addNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
LiLCalculations.setFirstDigit(true);
LiLCalculations.setCalcSelect(1);
LiLCalculations.setFirstNumber(x);
}
});
multNumbers = new JButton("*");
multNumbers.setFont(new Font("Tahoma", Font.PLAIN, 9));
multNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
LiLCalculations.setFirstDigit(true);
LiLCalculations.setCalcSelect(3);
LiLCalculations.setFirstNumber(x);
}
});
equalTo = new JButton("=");
equalTo.setFont(new Font("Tahoma", Font.PLAIN, 9));
equalTo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long y = Long.parseLong(textField.getText());
long z = LiLCalculations.getFirstNumber();
long ans = LiLCalculations.result(y, z);
textField.setText(Long.toString(ans));
LiLCalculations.setFirstDigit(true);
}
});
clearAll = new JButton("Clear All");
clearAll.setFont(new Font("Tahoma", Font.PLAIN, 9));
clearAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textField.setText("0");
LiLCalculations.setFirstDigit(true);
}
});
JButton optionSelect = new JButton("Options");
optionSelect.setFont(new Font("Tahoma", Font.PLAIN, 9));
optionSelect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
optionSelect.setEnabled(false);
}
});
JButton negativeNumbers = new JButton("+/-");
negativeNumbers.setFont(new Font("Tahoma", Font.PLAIN, 9));
negativeNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
x = x * -1;
textField.setText(Long.toString(x));
}
});
JRadioButton twoDecimalPlaces = new JRadioButton("2");
panel.add(twoDecimalPlaces);
panel.setVisible(false);
twoDecimalPlaces.setVisible(false);
JRadioButton fourDecimalPlaces = new JRadioButton("4");
fourDecimalPlaces.setSelected(true);
panel.add(fourDecimalPlaces);
fourDecimalPlaces.setVisible(false);
JRadioButton otherRadio = new JRadioButton("Other");
panel.add(otherRadio);
otherRadio.setVisible(false);
GroupLayout gl_contentPane = new GroupLayout(contentPane);
JButton decimalPoint = new JButton(".");
decimalPoint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(integerMode.isSelected() == true){
decimalPoint.disable();
} else {
double x = Double.parseDouble(textField.getText());
if(LiLCalculations.firstDigit() == true){
textField.setText("." + Double.toString(x));
} else {
textField.setText( Double.toString(x) + ".");
}
decimalPoint.disable();
}
}
});
JCheckBox integerMode = new JCheckBox("Integer Arithmetic", true);
integerMode.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getSource() == integerMode){
if(integerMode.isSelected() == false){
JSpinner spinner = new JSpinner();
spinner.setVisible(false);
spinner.setModel(new SpinnerNumberModel(0, 0, 10, 1));
panel.add(spinner);
contentPane.setLayout(gl_contentPane);
setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{contentPane, button1, button2, button3,
button4, button5, button6, button7, button8, button9,
button0, decimalPoint, addNumbers, subNumbers, multNumbers, divNumbers,
equalTo, negativeNumbers, clearAll, optionSelect, textField}));
otherRadio.setVisible(true);
panel.setVisible(true);
fourDecimalPlaces.setVisible(true);
twoDecimalPlaces.setVisible(true);
otherRadio.setVisible(true);
}
}
}
});
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(textField)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(button1, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(button7, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button4, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addComponent(decimalPoint, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(button5, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button2, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(button3, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button6, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(button8, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(button9, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addComponent(button0, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(subNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(multNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(divNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(addNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(negativeNumbers, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(equalTo, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clearAll, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
.addComponent(optionSelect, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGap(18)
.addComponent(separator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(integerMode, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(okButton, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
.addComponent(panel, 0, 0, Short.MAX_VALUE))
.addContainerGap())
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(18)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
.addGap(3)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(button1, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button2, GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
.addComponent(button3, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(addNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(negativeNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(button6, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button5, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button4, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(subNumbers, GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
.addComponent(equalTo, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(button7, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button8, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button9, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(multNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(optionSelect, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(decimalPoint, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button0, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(divNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(clearAll, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGap(25))
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(separator, GroupLayout.PREFERRED_SIZE, 241, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(29)
.addComponent(integerMode)
.addGap(18)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)
.addGap(26)
.addComponent(okButton, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}
这是我从 window 查看器那里得到的错误:
``
Internal Error
WindowBuilder encountered unexpected internal error.
This could be caused by a WindowBuilder bug or by a misconfiguration issue, conflict, partial update, etc.
> org.eclipse.wb.internal.core.utils.check.AssertionFailedException:
> {new: javax.swing.JButton} {local-unique: decimalPoint} {/new
> JButton(".")/ /decimalPoint.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent e) {
> if(integerMode.isSelected() == true){ decimalPoint.disable(); } else {
> double x = Double.parseDouble(textField.getText());
> if(LiLCalculations.firstDigit() == true){ textField.setText("." +
> Double.toString(x)); } else { textField.setText( Double.toString(x) +
> "."); } decimalPoint.disable(); } } })/} is not created at after
> GroupLayout gl_contentPane=new GroupLayout(contentPane); in package
> calculators; import java.awt.BorderLayout; import java.awt.EventQueue;
> import javax.swing.Box; import javax.swing.JFrame; import
> javax.swing.JPanel; import javax.swing.border.EmptyBorder; import
> javax.swing.JButton; import java.awt.event.ActionListener; import
> java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import
> java.awt.event.ItemListener; import javax.swing.JTextField; import
> javax.swing.JLabel; import java.awt.FlowLayout; import
> net.miginfocom.swing.MigLayout; import javax.swing.GroupLayout; import
> javax.swing.GroupLayout.Alignment; import java.awt.Component; import
> javax.swing.LayoutStyle.ComponentPlacement; import
> javax.swing.SwingConstants; import javax.swing.JDesktopPane; import
> org.eclipse.wb.swing.FocusTraversalOnArray; import
> javax.swing.JSeparator; import java.awt.Color; import
> javax.swing.JCheckBox; import javax.swing.JRadioButton; import
> javax.swing.border.TitledBorder; import javax.swing.JSpinner; import
> javax.swing.SpinnerNumberModel; import java.awt.Font; public class
> LiLCalculator extends JFrame { private JPanel contentPane; private
> JTextField textField; JButton button0; JButton button1; JButton
> button2; JButton button3; JButton button4; JButton button5; JButton
> button6; JButton button7; JButton button8; JButton button9; JButton
> addNumbers; JButton subNumbers; JButton multNumbers; JButton
> divNumbers; JButton equalTo; JButton clearAll; JCheckBox integerMode;
> /** * Launch the application. */ public static void main(String[]
> args) { EventQueue.invokeLater(new Runnable() { public void run() {
> try { LiLCalculator frame = new LiLCalculator();
> frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); }
> } }); } /** * Create the frame. */ public LiLCalculator() {
> setTitle("Lil Calculator"); JSeparator separator = new JSeparator();
> separator.setOrientation(SwingConstants.VERTICAL);
> separator.setForeground(Color.BLACK); separator.setVisible(false);
> JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(null,
> "Precision", TitledBorder.LEADING, TitledBorder.TOP, null, null));
> panel.setVisible(false); JButton okButton = new JButton("<<< ``
我会 post 一张我希望我的计算器模型看起来如何与现在看起来如何的图片,但我没有足够的声誉,但我想知道为什么计算器组件忽略了我的说明并且只是出现在一条直线上。另外,我想知道是否有人知道这个错误是什么?由于 Window 构建器的错误,我不得不多次重新启动 eclipse,并且想知道我可以做些什么来修复它。非常感谢。
(如果需要,我可以 post 完整的堆栈错误,我实际上不确定如何像代码一样格式化我的错误,所以有人可以编辑它以使其看起来像在代码块?)
编辑:请问为什么这个问题被否决了?
修复重复代码后,您还需要修复一些其他问题。
- 您需要在顶部添加
public class LilCalculator extends JFrame {
- 为了让您的 GUI 正确显示,您需要像这样将 GroupLayout 添加到您的 contentPane
contentPane.setLayout(gl_contentPane);
- 那么你应该小心你如何使用变量,因为其中一些变量在你的事件中是不可见的
- 尝试在使用 WindowBuilder 进行每次更改后查看代码,并尝试理解为什么它会以这种方式生成。
- 尝试修改代码并观察 GUI 中的变化
我正在尝试使用 JSwing api 制作一个计算器。我完成了大约一半,得到了计算器,因此它的大部分功能都可以使用,但是当我在后面运行编写一些代码以使其更整洁并向计算器添加一些新选项时,但我运行 变成一个问题。当我运行它的时候,计算器的格式全错了,但是没有编辑源码。当我尝试使用 GUI 更改它时,window 生成器吐出一个错误。
这是我正在使用的代码:
package calculators;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.FlowLayout;
import net.miginfocom.swing.MigLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Component;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.JDesktopPane;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import javax.swing.JSeparator;
import java.awt.Color;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.border.TitledBorder;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import java.awt.Font;
private JPanel contentPane;
private JTextField textField;
JButton button0;
JButton button1;
JButton button2;
JButton button3;
JButton button4;
JButton button5;
JButton button6;
JButton button7;
JButton button8;
JButton button9;
JButton addNumbers;
JButton subNumbers;
JButton multNumbers;
JButton divNumbers;
JButton equalTo;
JButton clearAll;
JCheckBox integerMode;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LiLCalculator frame = new LiLCalculator();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public LiLCalculator() {
setTitle("Lil Calculator");
JSeparator separator = new JSeparator();
separator.setOrientation(SwingConstants.VERTICAL);
separator.setForeground(Color.BLACK);
separator.setVisible(false);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "Precision", TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel.setVisible(false);
JButton okButton = new JButton("<<<<OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 470, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
textField = new JTextField();
textField.setEditable(false);
textField.setHorizontalAlignment(SwingConstants.RIGHT);
textField.setText("0");
textField.setColumns(10);
JLabel label = new JLabel("");
button1 = new JButton("1");
button1.setFont(new Font("Tahoma", Font.PLAIN, 9));
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("1");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "1");
}
});
button2 = new JButton("2");
button2.setFont(new Font("Tahoma", Font.PLAIN, 9));
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("2");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "2");
}
});
button4 = new JButton("4");
button4.setFont(new Font("Tahoma", Font.PLAIN, 9));
button4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("4");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "4");
}
});
button5 = new JButton("5");
button5.setFont(new Font("Tahoma", Font.PLAIN, 9));
button5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("5");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "5");
}
});
button3 = new JButton("3");
button3.setFont(new Font("Tahoma", Font.PLAIN, 9));
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("3");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "3");
}
});
button6 = new JButton("6");
button6.setFont(new Font("Tahoma", Font.PLAIN, 9));
button6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("6");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "6");
}
});
button7 = new JButton("7");
button7.setFont(new Font("Tahoma", Font.PLAIN, 9));
button7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("7");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "7");
}
});
button8 = new JButton("8");
button8.setFont(new Font("Tahoma", Font.PLAIN, 9));
button8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("8");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "8");
}
});
button9 = new JButton("9");
button9.setFont(new Font("Tahoma", Font.PLAIN, 9));
button9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("9");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "9");
}
});
button0 = new JButton("0");
button0.setFont(new Font("Tahoma", Font.PLAIN, 9));
button0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(LiLCalculations.firstDigit()){
textField.setText("0");
LiLCalculations.setFirstDigit(false);
} else
textField.setText(textField.getText() + "0");
}
});
subNumbers = new JButton("-");
subNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
LiLCalculations.setFirstDigit(true);
LiLCalculations.setCalcSelect(2);
LiLCalculations.setFirstNumber(x);
}
});
divNumbers = new JButton("/");
divNumbers.setFont(new Font("Tahoma", Font.PLAIN, 9));
divNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
button0.setEnabled(false);
LiLCalculations.setFirstDigit(true);
LiLCalculations.setCalcSelect(4);
LiLCalculations.setFirstNumber(x);
}
});
addNumbers = new JButton("+");
addNumbers.setFont(new Font("Tahoma", Font.PLAIN, 8));
addNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
LiLCalculations.setFirstDigit(true);
LiLCalculations.setCalcSelect(1);
LiLCalculations.setFirstNumber(x);
}
});
multNumbers = new JButton("*");
multNumbers.setFont(new Font("Tahoma", Font.PLAIN, 9));
multNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
LiLCalculations.setFirstDigit(true);
LiLCalculations.setCalcSelect(3);
LiLCalculations.setFirstNumber(x);
}
});
equalTo = new JButton("=");
equalTo.setFont(new Font("Tahoma", Font.PLAIN, 9));
equalTo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long y = Long.parseLong(textField.getText());
long z = LiLCalculations.getFirstNumber();
long ans = LiLCalculations.result(y, z);
textField.setText(Long.toString(ans));
LiLCalculations.setFirstDigit(true);
}
});
clearAll = new JButton("Clear All");
clearAll.setFont(new Font("Tahoma", Font.PLAIN, 9));
clearAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textField.setText("0");
LiLCalculations.setFirstDigit(true);
}
});
JButton optionSelect = new JButton("Options");
optionSelect.setFont(new Font("Tahoma", Font.PLAIN, 9));
optionSelect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
optionSelect.setEnabled(false);
}
});
JButton negativeNumbers = new JButton("+/-");
negativeNumbers.setFont(new Font("Tahoma", Font.PLAIN, 9));
negativeNumbers.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
long x = Long.parseLong(textField.getText());
x = x * -1;
textField.setText(Long.toString(x));
}
});
JRadioButton twoDecimalPlaces = new JRadioButton("2");
panel.add(twoDecimalPlaces);
panel.setVisible(false);
twoDecimalPlaces.setVisible(false);
JRadioButton fourDecimalPlaces = new JRadioButton("4");
fourDecimalPlaces.setSelected(true);
panel.add(fourDecimalPlaces);
fourDecimalPlaces.setVisible(false);
JRadioButton otherRadio = new JRadioButton("Other");
panel.add(otherRadio);
otherRadio.setVisible(false);
GroupLayout gl_contentPane = new GroupLayout(contentPane);
JButton decimalPoint = new JButton(".");
decimalPoint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(integerMode.isSelected() == true){
decimalPoint.disable();
} else {
double x = Double.parseDouble(textField.getText());
if(LiLCalculations.firstDigit() == true){
textField.setText("." + Double.toString(x));
} else {
textField.setText( Double.toString(x) + ".");
}
decimalPoint.disable();
}
}
});
JCheckBox integerMode = new JCheckBox("Integer Arithmetic", true);
integerMode.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getSource() == integerMode){
if(integerMode.isSelected() == false){
JSpinner spinner = new JSpinner();
spinner.setVisible(false);
spinner.setModel(new SpinnerNumberModel(0, 0, 10, 1));
panel.add(spinner);
contentPane.setLayout(gl_contentPane);
setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{contentPane, button1, button2, button3,
button4, button5, button6, button7, button8, button9,
button0, decimalPoint, addNumbers, subNumbers, multNumbers, divNumbers,
equalTo, negativeNumbers, clearAll, optionSelect, textField}));
otherRadio.setVisible(true);
panel.setVisible(true);
fourDecimalPlaces.setVisible(true);
twoDecimalPlaces.setVisible(true);
otherRadio.setVisible(true);
}
}
}
});
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(textField)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(button1, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
.addComponent(button7, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button4, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addComponent(decimalPoint, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_contentPane.createSequentialGroup()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(button5, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button2, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(button3, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button6, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)))
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(button8, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(button9, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addComponent(button0, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(subNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(multNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(divNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(addNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(negativeNumbers, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(equalTo, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clearAll, GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
.addComponent(optionSelect, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGap(18)
.addComponent(separator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(integerMode, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(okButton, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
.addComponent(panel, 0, 0, Short.MAX_VALUE))
.addContainerGap())
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(18)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
.addGap(3)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(button1, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button2, GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
.addComponent(button3, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(addNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(negativeNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(button6, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button5, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button4, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(subNumbers, GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
.addComponent(equalTo, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(button7, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button8, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button9, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(multNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(optionSelect, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
.addComponent(decimalPoint, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(button0, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(divNumbers, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addComponent(clearAll, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGap(25))
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(separator, GroupLayout.PREFERRED_SIZE, 241, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(29)
.addComponent(integerMode)
.addGap(18)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)
.addGap(26)
.addComponent(okButton, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}
这是我从 window 查看器那里得到的错误:
``
Internal Error
WindowBuilder encountered unexpected internal error.
This could be caused by a WindowBuilder bug or by a misconfiguration issue, conflict, partial update, etc.
> org.eclipse.wb.internal.core.utils.check.AssertionFailedException:
> {new: javax.swing.JButton} {local-unique: decimalPoint} {/new
> JButton(".")/ /decimalPoint.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent e) {
> if(integerMode.isSelected() == true){ decimalPoint.disable(); } else {
> double x = Double.parseDouble(textField.getText());
> if(LiLCalculations.firstDigit() == true){ textField.setText("." +
> Double.toString(x)); } else { textField.setText( Double.toString(x) +
> "."); } decimalPoint.disable(); } } })/} is not created at after
> GroupLayout gl_contentPane=new GroupLayout(contentPane); in package
> calculators; import java.awt.BorderLayout; import java.awt.EventQueue;
> import javax.swing.Box; import javax.swing.JFrame; import
> javax.swing.JPanel; import javax.swing.border.EmptyBorder; import
> javax.swing.JButton; import java.awt.event.ActionListener; import
> java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import
> java.awt.event.ItemListener; import javax.swing.JTextField; import
> javax.swing.JLabel; import java.awt.FlowLayout; import
> net.miginfocom.swing.MigLayout; import javax.swing.GroupLayout; import
> javax.swing.GroupLayout.Alignment; import java.awt.Component; import
> javax.swing.LayoutStyle.ComponentPlacement; import
> javax.swing.SwingConstants; import javax.swing.JDesktopPane; import
> org.eclipse.wb.swing.FocusTraversalOnArray; import
> javax.swing.JSeparator; import java.awt.Color; import
> javax.swing.JCheckBox; import javax.swing.JRadioButton; import
> javax.swing.border.TitledBorder; import javax.swing.JSpinner; import
> javax.swing.SpinnerNumberModel; import java.awt.Font; public class
> LiLCalculator extends JFrame { private JPanel contentPane; private
> JTextField textField; JButton button0; JButton button1; JButton
> button2; JButton button3; JButton button4; JButton button5; JButton
> button6; JButton button7; JButton button8; JButton button9; JButton
> addNumbers; JButton subNumbers; JButton multNumbers; JButton
> divNumbers; JButton equalTo; JButton clearAll; JCheckBox integerMode;
> /** * Launch the application. */ public static void main(String[]
> args) { EventQueue.invokeLater(new Runnable() { public void run() {
> try { LiLCalculator frame = new LiLCalculator();
> frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); }
> } }); } /** * Create the frame. */ public LiLCalculator() {
> setTitle("Lil Calculator"); JSeparator separator = new JSeparator();
> separator.setOrientation(SwingConstants.VERTICAL);
> separator.setForeground(Color.BLACK); separator.setVisible(false);
> JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(null,
> "Precision", TitledBorder.LEADING, TitledBorder.TOP, null, null));
> panel.setVisible(false); JButton okButton = new JButton("<<< ``
我会 post 一张我希望我的计算器模型看起来如何与现在看起来如何的图片,但我没有足够的声誉,但我想知道为什么计算器组件忽略了我的说明并且只是出现在一条直线上。另外,我想知道是否有人知道这个错误是什么?由于 Window 构建器的错误,我不得不多次重新启动 eclipse,并且想知道我可以做些什么来修复它。非常感谢。
(如果需要,我可以 post 完整的堆栈错误,我实际上不确定如何像代码一样格式化我的错误,所以有人可以编辑它以使其看起来像在代码块?)
编辑:请问为什么这个问题被否决了?
修复重复代码后,您还需要修复一些其他问题。
- 您需要在顶部添加
public class LilCalculator extends JFrame {
- 为了让您的 GUI 正确显示,您需要像这样将 GroupLayout 添加到您的 contentPane
contentPane.setLayout(gl_contentPane);
- 那么你应该小心你如何使用变量,因为其中一些变量在你的事件中是不可见的
- 尝试在使用 WindowBuilder 进行每次更改后查看代码,并尝试理解为什么它会以这种方式生成。
- 尝试修改代码并观察 GUI 中的变化