当前位置: 代码迷 >> Eclipse >> 求各位大神帮小弟指正代码中的异常!多谢
  详细解决方案

求各位大神帮小弟指正代码中的异常!多谢

热度:28   发布时间:2016-04-23 01:07:50.0
求各位大神帮小弟指正代码中的错误!!!谢谢
package xiaomo;

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.*;

import javax.swing.*;

public class MessageFace extends JFrame{
public void CreateJFrame(String title){

//文本框的编辑
JTextField jt = new JTextField("Please enter static words to search...");
jt.setBackground(Color.pink);

//表格的设计
//JTable 的动态更新
String[] columnNames={"ID","Name","MobilePhone","Company","QQ number",};
String[][] tableValues={{"A1","B1","","",""},{"A2","B2","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","xxxxxxxxxxx","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
{"A3","B3","","",""},{"name-x","B4","","",""},{"A5","B5","","",""},
};
JTable table = new JTable(tableValues, columnNames);
JScrollPane scrollPane = new JScrollPane(table);

//对窗体的预处理
JFrame jf = new JFrame(title);
Container container = jf.getContentPane();
container.setBackground(Color.green);

// jf.setLayout(null);
jf.setBounds(900, 100, 415, 472); //(x,y,width,weight)
jf.setVisible(true);
// jf.setResizable(false);   //去掉最大化
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

//将面板划分为three个容器
JPanel jp1 = new JPanel(new GridLayout(1,1));
JPanel jp2 = new JPanel(new GridLayout(1,5,5,5));
JPanel jp3 = new JPanel(new GridLayout(1,1));
//组件所在副容器

//jp2的编辑
jp2.setBackground(Color.darkGray);
JButton jb1 = new JButton("Build");
jb1.setBackground(Color.lightGray);
JButton jb2 = new JButton("Edit");
JButton jb3 = new JButton("Delete");
JButton jb4 = new JButton("Search");
JButton jb5 = new JButton("Back");

jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new BuildButton(MessageFace.this,"").setVisible(true);
}
});

/*
 * 在设计代码时,要注重  程序的先后顺序,语言逻辑    否则就会出现启动程序时不显示,
 * 拖动一下才会显示的怪现象,其实这是逻辑的问题!!!
 */
jp1.add(scrollPane,BorderLayout.CENTER);
jp2.add(jb1);
jp2.add(jb2);
jp2.add(jb3);
jp2.add(jb4);
jp2.add(jb5);
jp3.add(jt);
container.add(jp3,BorderLayout.NORTH);
container.add(jp1,BorderLayout.CENTER);
container.add(jp2,BorderLayout.SOUTH);

}
public static void main(String[] args){
// TODO Auto-generated method stub
new MessageFace().CreateJFrame("People");
}


}

/*-----------------------------------------------------------------------*/
package xiaomo;

import java.sql.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

class BuildButton extends JDialog{
static Connection con;
static PreparedStatement sql;

public BuildButton(MessageFace messageface,String title){

super(messageface,"Please finish writing .",true);

//利用箱式布局管理器设计Name栏mb
//Birthday标签
Box IDBox = Box.createHorizontalBox();
IDBox.add(Box.createHorizontalStrut(30));
JLabel IDLabel = new JLabel("ID:");
IDBox.add(IDLabel);

IDBox.add(Box.createHorizontalStrut(20));
final JTextField IDTextField = new JTextField(30);
IDBox.add(IDTextField);
IDBox.add(Box.createHorizontalStrut(200));

//Name标签
Box NameBox = Box.createHorizontalBox();
// container.add(NameBox,BorderLayout.NORTH);
NameBox.add(Box.createHorizontalStrut(30));
JLabel NameLabel = new JLabel("NAME:");
NameBox.add(NameLabel);
  相关解决方案