给你段代吗参考参考
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TestFrame extends JFrame
public static void main(String args[]) {
try{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
TestFrame mainFrame = new TestFrame();
mainFrame.setSize(600, 400);
mainFrame.setLocation((screenSize.width - mainFrame.getSize().width) / 2,
(screenSize.height - mainFrame.getSize().height) / 2);
mainFrame.setTitle("Write Mail");
mainFrame.setVisible(true);
}
catch(Exception ex) {
}
} protected void processWindowEvent(WindowEvent we) {
super.processWindowEvent(we);
if (we.getID() == WindowEvent.WINDOW_CLOSING)
System.exit(0);
} public writeMailFrame() {
}}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class TestFrame extends JFrame
public static void main(String args[]) {
try{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
TestFrame mainFrame = new TestFrame();
mainFrame.setSize(600, 400);
mainFrame.setLocation((screenSize.width - mainFrame.getSize().width) / 2,
(screenSize.height - mainFrame.getSize().height) / 2);
mainFrame.setTitle("Write Mail");
mainFrame.setVisible(true);
}
catch(Exception ex) {
}
} protected void processWindowEvent(WindowEvent we) {
super.processWindowEvent(we);
if (we.getID() == WindowEvent.WINDOW_CLOSING)
System.exit(0);
} public writeMailFrame() {
}}
import javax.swing.*;public class TestFrame
{
public static void main(String args[]){
JFrame f=new JFrame("MY JFrame Example!");
Container c=f.getContentPane();
c.setLayout(new FlowLayout());
for (int i=0;i<5 ;i++ )
{
c.add(new JButton("My Button")).setBackground(SystemColor.control);
}
c.add (new JLabel ("Swing Test Frame"));
f.setSize(300,200);
f.show();
}
}这样可以了。
s是小写了2。程序末尾多了个分号