通信记录系统(2)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane.*;
import java.sql.*;

public class MainFrame extends JFrame {
   public MainFrame(){
     setTitle("通讯纪录本:");
     setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
     Container contentPane=getContentPane();
     //获得屏幕大小
     Toolkit kit=Toolkit.getDefaultToolkit();
     Dimension screenSize=kit.getScreenSize();
     int screenWidth=screenSize.width;
     int screenHeight=screenSize.height;
     setLocation(screenWidth/2-DEFAULT_WIDTH/2,screenHeight/2-DEFAULT_HEIGHT/2);
     ///////////////////////////////////////////////////
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     //添加菜单
     JMenuBar jMenuBar=new JMenuBar();
     JMenu jMenuFile=new JMenu("文件");
     JMenuItem jMIOpen=new JMenuItem("打开");
     jMenuFile.add(jMIOpen);
     jMenuBar.add(jMenuFile);
     setJMenuBar(jMenuBar);
     ///////////////////////////////////////////////////
     //添加窗体控件on right
     JButton jBadd=new JButton("添加");
     JButton jBchange=new JButton("修改");
     JButton jBdelete=new JButton("删除");
     bright=Box.createVerticalBox();
     bright.add(jBadd);
     bright.add(Box.createVerticalGlue());
     bright.add(jBchange);
     bright.add(Box.createVerticalGlue());
     bright.add(jBdelete);
     //////  jPanel1
     JPanel jPanel1=new JPanel(new GridLayout(5,2));
     JLabel jLname=new JLabel("姓  名:",JLabel.RIGHT);
     jLname.setBorder(BorderFactory.createLineBorder(Color.black));

/////////////////////////////这里怎么不能改变JLabel的大小呢?(只能放大,不能缩小)
     jLname.setPreferredSize(new Dimension(50,20));
     JTextField jTname=new JTextField(6);
     JLabel jLtelephone=new JLabel("电  话:",JLabel.RIGHT);
     jLtelephone.setPreferredSize(new Dimension(30,20));
     JTextField jTtelephone=new JTextField(10);
     JLabel jLemail=new JLabel("电子邮件:",JLabel.RIGHT);
     jLemail.setPreferredSize(new Dimension(100,25));
     JTextField jTemail=new JTextField(10);
     JLabel jLbirthday=new JLabel("生  日:",JLabel.RIGHT);
     jLbirthday.setPreferredSize(new Dimension(30,20));
     JTextField jTbirthday=new JTextField(12);
     jPanel1.add(jLname);
     jPanel1.add(jTname);
     jPanel1.add(jLtelephone);
     jPanel1.add(jTtelephone);
     jPanel1.add(jLemail);
     jPanel1.add(jTemail);
     jPanel1.add(jLbirthday);
     jPanel1.add(jTbirthday);
    
     /////   jPanel2
     JPanel jPanel2=new JPanel();
     JLabel jLimage=new JLabel("kkkkkkk");
     jLimage.setPreferredSize(new Dimension(200,140));
     jLimage.setBorder(BorderFactory.createLineBorder(Color.black));
     //jLimage.setBackground(Color.blue);
     jPanel2.add(jLimage);
     /////   jPleft
     jPleft=new JPanel(new FlowLayout());
     //
     JPanel jPtop=new JPanel(new FlowLayout());
     jPtop.setBorder(BorderFactory.createLineBorder(Color.blue));
     jPtop.add(jPanel1);
     jPtop.add(Box.createRigidArea(new Dimension(70,100)));
     jPtop.add(jPanel2);
     jPleft.add(jPtop);
     /////
    
     contentPane.add(bright,BorderLayout.WEST);
     contentPane.add(jPleft,BorderLayout.CENTER);
   }
   public static void main(String[] args){
     JFrame jFrame=new MainFrame();
     jFrame.show();
   }
   private int DEFAULT_WIDTH=600;
   private int DEFAULT_HEIGHT=400;
   private Box bright;
   private JPanel jPcenter;
   private JPanel jPleft;
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页