且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

简单的锐捷登录界面

更新时间:2022-09-16 23:19:19

最近学了JAVA的CUI,经常连接锐捷上网,自己就写了一个简单的锐捷登录界面(还有很多地方需要改善的)

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;


public class Ruijie_Frame extends JFrame implements ActionListener{
 String[] strLanguage = {"中文","English"};
 String[] strNet = {"RTL8168C(P)/8111C(P)","Wireless LAN"};
 Checkbox box = new Checkbox("保存密码");
 JPanel pnlNorth=new JPanel();
 JPanel pnlSOUTH = new JPanel();
 JPanel pnlCenter = new JPanel();
 JPanel pnlGrid = new JPanel();
 Box baseBox,box1,box2;
 ImageIcon image = new ImageIcon("ruijie.jpg");
 JLabel lblImage = new JLabel(image);
 JLabel lblSupplicant = new JLabel("Supplicant 3.95");
 JLabel lblUserName = new JLabel("用户名");
 JLabel lblPassword = new JLabel("密码");
 JLabel lblLanguage = new JLabel("language");
 JLabel lblNet = new JLabel("网络");
 JComboBox cboLanguage = new JComboBox(strLanguage);
 JComboBox cboNet = new JComboBox(strNet);
 JButton button1 = new JButton("连接");
 JButton button2 = new JButton("退出");
 JButton button3 = new JButton("消息管理");
 JButton button4 = new JButton("设置");
 
 public RuijieFrame(){
 

  box1=Box.createVerticalBox();
  box1.add(lblSupplicant);
  box1.add(Box.createVerticalStrut(12));
  box1.add(lblUserName);
  box1.add(Box.createVerticalStrut(12));
  box1.add(lblPassword);
  box1.add(Box.createVerticalStrut(12));
  box1.add(lblLanguage);
  box1.add(Box.createVerticalStrut(12));
  box1.add(lblNet);
  box1.add(Box.createVerticalStrut(12));

  
  box2=Box.createVerticalBox();
  box2.add(new JLabel("                              "));
  box2.add(Box.createVerticalStrut(5));
  box2.add(new JTextField(20));
  box2.add(Box.createVerticalStrut(5));
  box2.add(new JPasswordField(20));
  box2.add(Box.createVerticalStrut(5));
  box2.add(cboLanguage);
  box2.add(Box.createVerticalStrut(5));
  box2.add(cboNet);
  box2.add(Box.createVerticalStrut(5));
  
  baseBox=Box.createHorizontalBox();
  baseBox.add(box1);
  baseBox.add(Box.createHorizontalStrut(6));
  baseBox.add(box2);
  
  pnlNorth.add(lblImage);//添加图片
  
  pnlSOUTH.setLayout(new FlowLayout(FlowLayout.CENTER,15,10));
  pnlSOUTH.add(button1);
  pnlSOUTH.add(button2);
  pnlSOUTH.add(button3);
  pnlSOUTH.add(button4);
  
  pnlCenter.add(baseBox);
  
  add(pnlNorth,BorderLayout.NORTH);
  add(pnlCenter);
  add(pnlSOUTH,BorderLayout.SOUTH); 
  
  button2.addActionListener(this);//注册监听器
}
 public static void main(String[] args) {
  try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); //windows界面风格
  } catch (Exception e) {
   e.printStackTrace();
  }
   RuijieFrame frame = new RuijieFrame();
  ImageIcon logo = new ImageIcon("logo.png");//设置窗口左上角的小图标
  frame.setIconImage(logo.getImage());
  frame.setTitle("锐捷认证客户端");
  frame.setLocationRelativeTo(null);//窗口居中显示
  frame.setResizable(false);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(380,300);
  frame.setVisible(true);
    }

  public void actionPerformed(ActionEvent e) {
  if(e.getSource()==button2){
   
   //自定义对话框
   Object[] options = {"  确定  ","  取消  "};
   int n = JOptionPane.showOptionDialog(this, "     您是否要退出?","8021x",JOptionPane.YES_OPTION ,JOptionPane.PLAIN_MESSAGE,
                                    null, options, options[0] ) ;
            if(n == 0){
             System.exit(0);
            }
      }
 }
}
 

运行的效果:

简单的锐捷登录界面


本文转自 lingdududu 51CTO博客,原文链接: http://blog.51cto.com/liangruijun/619262