在编写图形用户界面时,编译没问题,最后报错
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class bookTypeAddInterFrame extends JInternalFrame {
private JTextField bookTypeNameTxt;
private JTextArea bookTypeDescTxt;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
bookTypeAddInterFrame frame = new bookTypeAddInterFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public bookTypeAddInterFrame() {
setIconifiable(true);
setClosable(true);
setTitle("图书类别添加");
setBounds(100, 100, 751, 461);
JLabel lblNewLabel = new JLabel("图书类别名称:");
lblNewLabel.setFont(new Font("华文行楷", Font.PLAIN, 20));
JLabel lblNewLabel_1 = new JLabel("图书类别描述:");
lblNewLabel_1.setFont(new Font("华文行楷", Font.PLAIN, 20));
bookTypeNameTxt = new JTextField();
bookTypeNameTxt.setColumns(10);
JButton btnNewButton = new JButton("添加");
btnNewButton.setIcon(new ImageIcon("C:\\Users\\zqt\\Desktop\\11\\add.png"));
JButton btnNewButton_1 = new JButton("重置");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
resetValueActionPerFormed(e);
}
});
btnNewButton_1.setIcon(new ImageIcon("C:\\Users\\zqt\\Desktop\\11\\reset.png"));
bookTypeDescTxt = new JTextArea();
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(147)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel)
.addComponent(lblNewLabel_1))
.addGap(41)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(bookTypeDescTxt)
.addComponent(bookTypeNameTxt, GroupLayout.PREFERRED_SIZE, 224, GroupLayout.PREFERRED_SIZE))
.addContainerGap(187, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup()
.addGap(199)
.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE)
.addGap(59)
.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 118, GroupLayout.PREFERRED_SIZE)
.addContainerGap(249, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap(74, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 51, GroupLayout.PREFERRED_SIZE)
.addComponent(bookTypeNameTxt, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(60)
.addComponent(lblNewLabel_1, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createSequentialGroup()
.addGap(40)
.addComponent(bookTypeDescTxt, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)))
.addGap(77)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
.addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE))
.addGap(102))
);
getContentPane().setLayout(groupLayout);
}
/**
* 重置事件处理(监听器)
* @param e
*/
protected void resetValueActionPerFormed(ActionEvent e) {
// TODO Auto-generated method stub
this.resetValue();
}
/**
* 重置表单
*/
private void resetValue() {
this.bookTypeNameTxt.setText("");
this.bookTypeDescTxt.setText("");
}
}
```运行结果一直是
请大神帮忙!!!!!
看看这篇博客,看能不能解决你的问题
https://blog.csdn.net/qq_38617531/article/details/103199349