我在JBUILDER9中写了一些代码,不知道为什么就是在运行时无法显示,代码如下
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class MainClass extends JFrame implements ActionListener
{
JLabel label=new JLabel("未建立连接");
JTextArea ta=new JTextArea();
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel(); JPanel p4=new JPanel();
JButton b1 = new JButton();
JTextField t2 = new JTextField();
JButton b2 = new JButton();
JButton b3 = new JButton();
JTextField t1 = new JTextField();
JButton b4 = new JButton(); public void MainClass() {
try {
jbInit();
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this); }
catch(Exception e) {
e.printStackTrace();
} }
// public static void main(String[] args) {
// MainClass mainClass = new MainClass(); //} private void jbInit() throws Exception {
t1=new JTextField();
t2=new JTextField(15);
label=new JLabel("未建立连接");
ta=new JTextArea();
ta.setEditable(false);
b1=new JButton("连接对方");
b2=new JButton("等待连接");
b3=new JButton("断开连接");
b4=new JButton("发送");
p1=new JPanel();
p1.setLayout(new FlowLayout());
t1.setCaretPosition(0);
t1.setEditable(true);
t1.setText("");
t1.setColumns(40);
t2.setText("");
this.setResizable(false);
this.setTitle("");
p1.add(b1);
p1.add(t2);
p1.add(b2);
p1.add(b3); p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.add(t1);
p2.add(b4); p3=new JPanel();
p3.setLayout(new GridLayout(2,1));
p3.add(ta);
p3.add(p2); p4=new JPanel();
p4.setLayout(new BorderLayout());
p4.add(p1,BorderLayout.NORTH);
p4.add(p3,BorderLayout.CENTER);
p4.add(label,BorderLayout.SOUTH); this.getContentPane().add(p4, BorderLayout.CENTER);
}
public void readStr(String s)
{
ta.append("对方:" + s.substring(5)+ "");
} public void actionPerformed(ActionEvent actionEvent) { }
}还有一个
import javax.swing.UIManager;
import java.awt.*;
import javax.swing.*;import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class main implements WindowListener{
boolean packFrame = false;
int m_nStatus=0;
//Construct the application
public main() {
MainClass frame = new MainClass();
frame.addWindowListener(this); frame.setSize(100,300);
frame.setVisible(true);
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new main();
} public void windowOpened(WindowEvent windowEvent) {
} public void windowClosing(WindowEvent windowEvent) {
} public void windowClosed(WindowEvent windowEvent) {
System.exit(0);
} public void windowIconified(WindowEvent windowEvent) {
} public void windowDeiconified(WindowEvent windowEvent) {
} public void windowActivated(WindowEvent windowEvent) {
} public void windowDeactivated(WindowEvent windowEvent) {
}
}上面代码能运行但是我定好的控件就是显示不了,请各位高人帮忙!!!!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class MainClass extends JFrame implements ActionListener
{
JLabel label=new JLabel("未建立连接");
JTextArea ta=new JTextArea();
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel(); JPanel p4=new JPanel();
JButton b1 = new JButton();
JTextField t2 = new JTextField();
JButton b2 = new JButton();
JButton b3 = new JButton();
JTextField t1 = new JTextField();
JButton b4 = new JButton(); public void MainClass() {
try {
jbInit();
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this); }
catch(Exception e) {
e.printStackTrace();
} }
// public static void main(String[] args) {
// MainClass mainClass = new MainClass(); //} private void jbInit() throws Exception {
t1=new JTextField();
t2=new JTextField(15);
label=new JLabel("未建立连接");
ta=new JTextArea();
ta.setEditable(false);
b1=new JButton("连接对方");
b2=new JButton("等待连接");
b3=new JButton("断开连接");
b4=new JButton("发送");
p1=new JPanel();
p1.setLayout(new FlowLayout());
t1.setCaretPosition(0);
t1.setEditable(true);
t1.setText("");
t1.setColumns(40);
t2.setText("");
this.setResizable(false);
this.setTitle("");
p1.add(b1);
p1.add(t2);
p1.add(b2);
p1.add(b3); p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.add(t1);
p2.add(b4); p3=new JPanel();
p3.setLayout(new GridLayout(2,1));
p3.add(ta);
p3.add(p2); p4=new JPanel();
p4.setLayout(new BorderLayout());
p4.add(p1,BorderLayout.NORTH);
p4.add(p3,BorderLayout.CENTER);
p4.add(label,BorderLayout.SOUTH); this.getContentPane().add(p4, BorderLayout.CENTER);
}
public void readStr(String s)
{
ta.append("对方:" + s.substring(5)+ "");
} public void actionPerformed(ActionEvent actionEvent) { }
}还有一个
import javax.swing.UIManager;
import java.awt.*;
import javax.swing.*;import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class main implements WindowListener{
boolean packFrame = false;
int m_nStatus=0;
//Construct the application
public main() {
MainClass frame = new MainClass();
frame.addWindowListener(this); frame.setSize(100,300);
frame.setVisible(true);
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new main();
} public void windowOpened(WindowEvent windowEvent) {
} public void windowClosing(WindowEvent windowEvent) {
} public void windowClosed(WindowEvent windowEvent) {
System.exit(0);
} public void windowIconified(WindowEvent windowEvent) {
} public void windowDeiconified(WindowEvent windowEvent) {
} public void windowActivated(WindowEvent windowEvent) {
} public void windowDeactivated(WindowEvent windowEvent) {
}
}上面代码能运行但是我定好的控件就是显示不了,请各位高人帮忙!!!!
public void MainClass()
改成
public MainClass()