关于java 继承的JFrame的类显示不出里面的容器
//登录处方界面的类importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.sql....
//登录处方界面的类
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
@SuppressWarnings("serial")
public class Surface extends JFrame implements ActionListener{
Connection con;
Statement stmt;
ResultSet rs;
String nm;
JButton btque,btupd,btinc,btdel,btvie,btext;
JTextField tfld,tfld1,tfld2,tfld3,tfld4,tfld5,tfld6,tfld7,tfld8,tfld9;
Surface(){
super("处方跟踪系统PTS");
setSize(360,480);
setLocation(420,200);
setVisible(true);
JPanel panel1 = new JPanel();
panel1.setSize(340,450);
panel1.setLayout(null);
setBackground(Color.cyan);
btque=new JButton("查询");
btupd=new JButton("修改");
btinc=new JButton("添加");
btdel=new JButton("删除");
btvie=new JButton("显示");
btext=new JButton("退出");
panel1.add(btque); panel1.add(btupd); panel1.add(btinc);
panel1.add(btdel); panel1.add(btvie); panel1.add(btext);
JLabel lb=new JLabel("处方ID号:");
...
JLabel lb9=new JLabel("手机号:");
tfld1=new JTextField();
...
tfld9=new JTextField();
panel1.add(lb);panel1.add(tfld);
panel1.add(lb1);panel1.add(tfld1);
...
panel1.add(lb9);panel1.add(tfld9);
btque.setBounds(50,50,50,30);
btupd.setBounds(140,50,50,30);
btvie.setBounds(230,50,50,30);
btinc.setBounds(50,110,50,30);
btdel.setBounds(140,110,50,30);
btext.setBounds(230,110,50,30);
lb.setBounds(30,170,40,20);
tfld.setBounds(80,170,200,20);
lb1.setBounds(30,210,40,20);
tfld1.setBounds(80,210,200,20);
lb2.setBounds(30,240,40,20);
tfld2.setBounds(80,240,200,20);
lb3.setBounds(30,270,40,20);
tfld3.setBounds(80,270,200,20);
lb4.setBounds(30,300,40,20);
tfld4.setBounds(80,300,200,20);
lb5.setBounds(30,330,40,20);
tfld5.setBounds(80,330,200,20);
lb6.setBounds(30,360,40,20);
tfld6.setBounds(80,360,50,20);
lb7.setBounds(30,390,40,20);
tfld7.setBounds(80,390,50,20);
lb8.setBounds(160,360,40,20);
tfld8.setBounds(210,360,200,20);
lb9.setBounds(160,390,40,20);
tfld9.setBounds(210,390,200,20);
Container container = this.getContentPane();
container.add(panel1);
btque.addActionListener(this);
btupd.addActionListener(this);
btinc.addActionListener(this);
btdel.addActionListener(this);
btvie.addActionListener(this);
btext.addActionListener(this);
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});
}
}
//主类
public class PTStest {
public static void main(String[] args) {
new Surface();
}
}
多谢ms892认真的对待我的问题,参照ms892的代码我在完整的代码上只改动了一个地方,就是在
tfld1 = new JTextField();
tfld2 = new JTextField();
tfld3 = new JTextField();
tfld4 = new JTextField();
tfld5 = new JTextField();
tfld6 = new JTextField();
tfld7 = new JTextField();
tfld8 = new JTextField();
前面加了句 tfld = new JTextField();
漏定义tfld了,但是我不知道影响为什么会这么大,有谁能解答 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
@SuppressWarnings("serial")
public class Surface extends JFrame implements ActionListener{
Connection con;
Statement stmt;
ResultSet rs;
String nm;
JButton btque,btupd,btinc,btdel,btvie,btext;
JTextField tfld,tfld1,tfld2,tfld3,tfld4,tfld5,tfld6,tfld7,tfld8,tfld9;
Surface(){
super("处方跟踪系统PTS");
setSize(360,480);
setLocation(420,200);
setVisible(true);
JPanel panel1 = new JPanel();
panel1.setSize(340,450);
panel1.setLayout(null);
setBackground(Color.cyan);
btque=new JButton("查询");
btupd=new JButton("修改");
btinc=new JButton("添加");
btdel=new JButton("删除");
btvie=new JButton("显示");
btext=new JButton("退出");
panel1.add(btque); panel1.add(btupd); panel1.add(btinc);
panel1.add(btdel); panel1.add(btvie); panel1.add(btext);
JLabel lb=new JLabel("处方ID号:");
...
JLabel lb9=new JLabel("手机号:");
tfld1=new JTextField();
...
tfld9=new JTextField();
panel1.add(lb);panel1.add(tfld);
panel1.add(lb1);panel1.add(tfld1);
...
panel1.add(lb9);panel1.add(tfld9);
btque.setBounds(50,50,50,30);
btupd.setBounds(140,50,50,30);
btvie.setBounds(230,50,50,30);
btinc.setBounds(50,110,50,30);
btdel.setBounds(140,110,50,30);
btext.setBounds(230,110,50,30);
lb.setBounds(30,170,40,20);
tfld.setBounds(80,170,200,20);
lb1.setBounds(30,210,40,20);
tfld1.setBounds(80,210,200,20);
lb2.setBounds(30,240,40,20);
tfld2.setBounds(80,240,200,20);
lb3.setBounds(30,270,40,20);
tfld3.setBounds(80,270,200,20);
lb4.setBounds(30,300,40,20);
tfld4.setBounds(80,300,200,20);
lb5.setBounds(30,330,40,20);
tfld5.setBounds(80,330,200,20);
lb6.setBounds(30,360,40,20);
tfld6.setBounds(80,360,50,20);
lb7.setBounds(30,390,40,20);
tfld7.setBounds(80,390,50,20);
lb8.setBounds(160,360,40,20);
tfld8.setBounds(210,360,200,20);
lb9.setBounds(160,390,40,20);
tfld9.setBounds(210,390,200,20);
Container container = this.getContentPane();
container.add(panel1);
btque.addActionListener(this);
btupd.addActionListener(this);
btinc.addActionListener(this);
btdel.addActionListener(this);
btvie.addActionListener(this);
btext.addActionListener(this);
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});
}
}
//主类
public class PTStest {
public static void main(String[] args) {
new Surface();
}
}
多谢ms892认真的对待我的问题,参照ms892的代码我在完整的代码上只改动了一个地方,就是在
tfld1 = new JTextField();
tfld2 = new JTextField();
tfld3 = new JTextField();
tfld4 = new JTextField();
tfld5 = new JTextField();
tfld6 = new JTextField();
tfld7 = new JTextField();
tfld8 = new JTextField();
前面加了句 tfld = new JTextField();
漏定义tfld了,但是我不知道影响为什么会这么大,有谁能解答 展开
展开全部
改成下面这样 再运行你的主类 就可以了 我在我本机测试通过的 还有 你的按钮的大小设置太小了 都显示不出来汉字 只显示...再设大点就OK
回答补充:你tfld这个变量没有初始化 就引用 程序就会报空指针异常 有了异常 程序就不会再往下运行了 所以这个错误对你的程序是致命
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Surface extends JFrame implements ActionListener {
Connection con;
Statement stmt;
ResultSet rs;
String nm;
JButton btque, btupd, btinc, btdel, btvie, btext;
JTextField tfld, tfld1, tfld2, tfld3, tfld4, tfld5, tfld6, tfld7, tfld8,
tfld9;
Surface() {
super("处方跟踪系统PTS");
setSize(360, 480);
setLocation(420, 200);
setVisible(true);
JPanel panel1 = new JPanel();
panel1.setSize(340, 450);
panel1.setLayout(null);
setBackground(Color.cyan);
btque = new JButton("查询");
btupd = new JButton("修改");
btinc = new JButton("添加");
btdel = new JButton("删除");
btvie = new JButton("显示");
btext = new JButton("退出");
panel1.add(btque);
panel1.add(btupd);
panel1.add(btinc);
panel1.add(btdel);
panel1.add(btvie);
panel1.add(btext);
JLabel lb = new JLabel("处方ID号:");
JLabel lb1 = new JLabel("处方ID号:");
JLabel lb2 = new JLabel("处方ID号:");
JLabel lb3 = new JLabel("处方ID号:");
JLabel lb4 = new JLabel("处方ID号:");
JLabel lb5 = new JLabel("处方ID号:");
JLabel lb6 = new JLabel("处方ID号:");
JLabel lb7 = new JLabel("处方ID号:");
JLabel lb8 = new JLabel("处方ID号:");
JLabel lb9 = new JLabel("手机号:");
tfld = new JTextField();
tfld1 = new JTextField();
tfld2 = new JTextField();
tfld3 = new JTextField();
tfld4 = new JTextField();
tfld5 = new JTextField();
tfld6 = new JTextField();
tfld7 = new JTextField();
tfld8 = new JTextField();
tfld9 = new JTextField();
panel1.add(lb);
panel1.add(tfld);
panel1.add(lb1);
panel1.add(tfld1);
panel1.add(lb2);
panel1.add(tfld2);
panel1.add(lb3);
panel1.add(tfld3);
panel1.add(lb4);
panel1.add(tfld4);
panel1.add(lb5);
panel1.add(tfld5);
panel1.add(lb6);
panel1.add(tfld6);
panel1.add(lb7);
panel1.add(tfld7);
panel1.add(lb8);
panel1.add(tfld8);
panel1.add(lb9);
panel1.add(tfld9);
btque.setBounds(50, 50, 50, 30);
btupd.setBounds(140, 50, 50, 30);
btvie.setBounds(230, 50, 50, 30);
btinc.setBounds(50, 110, 50, 30);
btdel.setBounds(140, 110, 50, 30);
btext.setBounds(230, 110, 50, 30);
lb.setBounds(30, 170, 40, 20);
tfld.setBounds(80, 170, 200, 20);
lb1.setBounds(30, 210, 40, 20);
tfld1.setBounds(80, 210, 200, 20);
lb2.setBounds(30, 240, 40, 20);
tfld2.setBounds(80, 240, 200, 20);
lb3.setBounds(30, 270, 40, 20);
tfld3.setBounds(80, 270, 200, 20);
lb4.setBounds(30, 300, 40, 20);
tfld4.setBounds(80, 300, 200, 20);
lb5.setBounds(30, 330, 40, 20);
tfld5.setBounds(80, 330, 200, 20);
lb6.setBounds(30, 360, 40, 20);
tfld6.setBounds(80, 360, 50, 20);
lb7.setBounds(30, 390, 40, 20);
tfld7.setBounds(80, 390, 50, 20);
lb8.setBounds(160, 360, 40, 20);
tfld8.setBounds(210, 360, 200, 20);
lb9.setBounds(160, 390, 40, 20);
tfld9.setBounds(210, 390, 200, 20);
Container container = this.getContentPane();
container.add(panel1);
btque.addActionListener(this);
btupd.addActionListener(this);
btinc.addActionListener(this);
btdel.addActionListener(this);
btvie.addActionListener(this);
btext.addActionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
//主类
public class PTStest {
public static void main(String[] args) {
new Surface();
}
}
回答补充:你tfld这个变量没有初始化 就引用 程序就会报空指针异常 有了异常 程序就不会再往下运行了 所以这个错误对你的程序是致命
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Surface extends JFrame implements ActionListener {
Connection con;
Statement stmt;
ResultSet rs;
String nm;
JButton btque, btupd, btinc, btdel, btvie, btext;
JTextField tfld, tfld1, tfld2, tfld3, tfld4, tfld5, tfld6, tfld7, tfld8,
tfld9;
Surface() {
super("处方跟踪系统PTS");
setSize(360, 480);
setLocation(420, 200);
setVisible(true);
JPanel panel1 = new JPanel();
panel1.setSize(340, 450);
panel1.setLayout(null);
setBackground(Color.cyan);
btque = new JButton("查询");
btupd = new JButton("修改");
btinc = new JButton("添加");
btdel = new JButton("删除");
btvie = new JButton("显示");
btext = new JButton("退出");
panel1.add(btque);
panel1.add(btupd);
panel1.add(btinc);
panel1.add(btdel);
panel1.add(btvie);
panel1.add(btext);
JLabel lb = new JLabel("处方ID号:");
JLabel lb1 = new JLabel("处方ID号:");
JLabel lb2 = new JLabel("处方ID号:");
JLabel lb3 = new JLabel("处方ID号:");
JLabel lb4 = new JLabel("处方ID号:");
JLabel lb5 = new JLabel("处方ID号:");
JLabel lb6 = new JLabel("处方ID号:");
JLabel lb7 = new JLabel("处方ID号:");
JLabel lb8 = new JLabel("处方ID号:");
JLabel lb9 = new JLabel("手机号:");
tfld = new JTextField();
tfld1 = new JTextField();
tfld2 = new JTextField();
tfld3 = new JTextField();
tfld4 = new JTextField();
tfld5 = new JTextField();
tfld6 = new JTextField();
tfld7 = new JTextField();
tfld8 = new JTextField();
tfld9 = new JTextField();
panel1.add(lb);
panel1.add(tfld);
panel1.add(lb1);
panel1.add(tfld1);
panel1.add(lb2);
panel1.add(tfld2);
panel1.add(lb3);
panel1.add(tfld3);
panel1.add(lb4);
panel1.add(tfld4);
panel1.add(lb5);
panel1.add(tfld5);
panel1.add(lb6);
panel1.add(tfld6);
panel1.add(lb7);
panel1.add(tfld7);
panel1.add(lb8);
panel1.add(tfld8);
panel1.add(lb9);
panel1.add(tfld9);
btque.setBounds(50, 50, 50, 30);
btupd.setBounds(140, 50, 50, 30);
btvie.setBounds(230, 50, 50, 30);
btinc.setBounds(50, 110, 50, 30);
btdel.setBounds(140, 110, 50, 30);
btext.setBounds(230, 110, 50, 30);
lb.setBounds(30, 170, 40, 20);
tfld.setBounds(80, 170, 200, 20);
lb1.setBounds(30, 210, 40, 20);
tfld1.setBounds(80, 210, 200, 20);
lb2.setBounds(30, 240, 40, 20);
tfld2.setBounds(80, 240, 200, 20);
lb3.setBounds(30, 270, 40, 20);
tfld3.setBounds(80, 270, 200, 20);
lb4.setBounds(30, 300, 40, 20);
tfld4.setBounds(80, 300, 200, 20);
lb5.setBounds(30, 330, 40, 20);
tfld5.setBounds(80, 330, 200, 20);
lb6.setBounds(30, 360, 40, 20);
tfld6.setBounds(80, 360, 50, 20);
lb7.setBounds(30, 390, 40, 20);
tfld7.setBounds(80, 390, 50, 20);
lb8.setBounds(160, 360, 40, 20);
tfld8.setBounds(210, 360, 200, 20);
lb9.setBounds(160, 390, 40, 20);
tfld9.setBounds(210, 390, 200, 20);
Container container = this.getContentPane();
container.add(panel1);
btque.addActionListener(this);
btupd.addActionListener(this);
btinc.addActionListener(this);
btdel.addActionListener(this);
btvie.addActionListener(this);
btext.addActionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
//主类
public class PTStest {
public static void main(String[] args) {
new Surface();
}
}
展开全部
没有设置显示,构造方法里加上setVisible(true),或是创建对象后调用show()方法都可以,不过show已经过时,所以建议使用setVisible
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在Surface()中增加
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);试试
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在Surface()中增加
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询