我是 intellij idea 和 jFormDesigner 的新手。我想测试我的应用程序。我将 jFormDesigner 文件添加到我的项目中,创建了表单并添加了简单的按钮和文本区域。我为按钮添加了鼠标单击事件,但我不知道如何测试它。
这是事件处理程序:
private void startButtonMouseClicked(MouseEvent e) {
resultTextField.setText("hello!");
}
这里是由intellijidea生成的代码:
public class SysJournalForm extends JFrame {
public SysJournalForm() {
initComponents();
}
public static void main(String [] args)
{
}
private void startButtonMouseClicked(MouseEvent e) {
resultTextField.setText("hello!");
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
// Generated using JFormDesigner Evaluation license - Vadim Mirgorod
scrollPane1 = new JScrollPane();
resultTextField = new JTextPane();
startButton = new JButton();
stopButton = new JButton();
//======== this ========
Container contentPane = getContentPane();
contentPane.setLayout(null);
//======== scrollPane1 ========
{
//---- resultTextField ----
resultTextField.setText("test");
scrollPane1.setViewportView(resultTextField);
}
contentPane.add(scrollPane1);
scrollPane1.setBounds(5, 5, 530, 295);
//---- startButton ----
startButton.setText("\u0441\u0442\u0430\u0440\u0442");
startButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
startButtonMouseClicked(e);
}
});
contentPane.add(startButton);
startButton.setBounds(5, 305, 130, startButton.getPreferredSize().height);
//---- stopButton ----
stopButton.setText("\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c");
contentPane.add(stopButton);
stopButton.setBounds(140, 305, 130, stopButton.getPreferredSize().height);
{ // compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = contentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
}
pack();
setLocationRelativeTo(getOwner());
// JFormDesigner - End of component initialization //GEN-END:initComponents
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
// Generated using JFormDesigner Evaluation license - Vadim Mirgorod
private JScrollPane scrollPane1;
private JTextPane resultTextField;
private JButton startButton;
private JButton stopButton;
// JFormDesigner - End of variables declaration //GEN-END:variables
}
当我单击 jFormDesigner 表单中的测试表单时,表单可以工作但没有事件。如何测试事件?