下面是代码:
import javax.swing.*;
import java.awt.*;
public class exe1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame();
f.setTitle("FirstFream");
f.setSize(300,300);
JLabel LabOne=new JLabel("这是标签");
JTextField txtOne=new JTextField("这是文本框");
JPanel p=new JPanel();
p.add(LabOne);
p.add(txtOne);
Border border=BorderFactory.createEtchedBorder();
p.setBorder(border);
Container contentPane=f.getContentPane();
contentPane.add(p);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.show();
}
}
------解决方案--------------------------------------------------------
- Java code
import javax.swing.*;import java.awt.*;public class Exe1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub JFrame f = new JFrame("FirstFream"); f.setSize(300,300); JLabel LabOne = new JLabel("这是标签"); JTextField txtOne = new JTextField("这是文本框"); JPanel p = new JPanel(); p.add(LabOne); p.add(txtOne); p.setBorder(BorderFactory.createEtchedBorder()); Container contentPane = f.getContentPane(); contentPane.add(p); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }}