package text6; import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class domo extends JFrame implements ActionListener{ JPanel jp1=new JPanel(); JPanel jp2=new JPanel(); JLabel lbl_no=new JLabel("学号"); JLabel lbl_name=new JLabel("姓名"); JLabel lbl_birth=new JLabel("生日"); JLabel lbl_sex=new JLabel("性别"); JLabel lbl_study=new JLabel("学情"); JLabel lbl_live=new JLabel("宿舍"); JTextField txt_no=new JTextField(20); JTextField txt_name=new JTextField(20); JTextField txt_birth=new JTextField(20); JTextField txt_sex=new JTextField(20); JTextField txt_study=new JTextField(20); JTextField txt_live=new JTextField(20); JButton btn_add=new JButton("新增"); JButton btn_delete=new JButton("删除"); JButton btn_update=new JButton("更新"); public domo(){ jp1.add(lbl_no); jp1.add(txt_no); jp1.add(lbl_name); jp1.add(txt_name); jp1.add(lbl_birth); jp1.add(txt_birth); jp1.add(lbl_sex); jp1.add(txt_sex); jp1.add(lbl_study); jp1.add(txt_birth); jp1.add(lbl_live); jp1.add(txt_live); add(jp1,BorderLayout.CENTER); jp2.add(btn_add); jp2.add(btn_delete); jp2.add(btn_update); add(jp2,BorderLayout.SOUTH); setBounds(250,250,250,250); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO 自动生成的方法存根 } public static void main(String args[]) { JFrame.setDefaultLookAndFeelDecorated(true); new domo(); } }改错
时间: 2024-03-17 17:47:05 浏览: 136
在代码中,lbl_study 和 txt_study 的添加顺序有误,应该是先添加标签 lbl_study,再添加文本框 txt_study。在代码中,txt_study 的添加应该替换为 txt_live。因此,正确的代码如下:
```
package text6;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class domo extends JFrame implements ActionListener{
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JLabel lbl_no=new JLabel("学号");
JLabel lbl_name=new JLabel("姓名");
JLabel lbl_birth=new JLabel("生日");
JLabel lbl_sex=new JLabel("性别");
JLabel lbl_study=new JLabel("学情");
JLabel lbl_live=new JLabel("宿舍");
JTextField txt_no=new JTextField(20);
JTextField txt_name=new JTextField(20);
JTextField txt_birth=new JTextField(20);
JTextField txt_sex=new JTextField(20);
JTextField txt_live=new JTextField(20);
JTextField txt_study=new JTextField(20);
JButton btn_add=new JButton("新增");
JButton btn_delete=new JButton("删除");
JButton btn_update=new JButton("更新");
public domo(){
jp1.add(lbl_no);
jp1.add(txt_no);
jp1.add(lbl_name);
jp1.add(txt_name);
jp1.add(lbl_birth);
jp1.add(txt_birth);
jp1.add(lbl_sex);
jp1.add(txt_sex);
jp1.add(lbl_study);
jp1.add(txt_study);
jp1.add(lbl_live);
jp1.add(txt_live);
add(jp1,BorderLayout.CENTER);
jp2.add(btn_add);
jp2.add(btn_delete);
jp2.add(btn_update);
add(jp2,BorderLayout.SOUTH);
setBounds(250,250,250,250);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
}
public static void main(String args[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
new domo();
}
}
```
阅读全文