zoukankan      html  css  js  c++  java
  • JAVA日志

    JAVA日志

    第二篇

    好难啊 ,某聊登录界面实现了对两个按钮的监听,界面的菜单栏,添加了下拉菜单,自己基础不好的原因吧,原本想出现界面之间的跳转可是发现自己只会加一个事件监听然后就没有了

    在账户登录和手机登录添加组件组合框(JComboBox)并初始化了他们,
    大部分还是在同学帮助下完成的,某聊登录界面的按钮添加由于自己不会设置布局开始就无法显示出来,同学帮忙设置了布局好像有点乱

    package 某聊;

    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JFrame;

    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;

    public class app {
    private JFrame frame;

    private JButton phoneerBtn;

    public app()
    {
        makeFrame();
    }
    //makeFrame()方法用来创建框架
    
    private void makeFrame()
    {
    	//创建框架并获得框架中的内容面板
        frame = new JFrame("某聊登录");        
        Container contentpane = frame.getContentPane();
        
        makeMenuBar();
        JPanel ok=new JPanel(new GridLayout(4,1));
    
        
      //创建组件
        JPanel yes= new JPanel(new FlowLayout());
        JPanel no = new JPanel(new FlowLayout());
    

    contentpane.add(ok);
    ok.add(yes);
    ok.add(no);
    JButton accounterbtn = new JButton("账户登录");
    no.add(accounterbtn);
    accounterbtn.addActionListener(new ActionListener(){

    		@Override
    		public void actionPerformed(ActionEvent arg0) {
    			// TODO Auto-generated method stub
    			String inputValue = JOptionPane.showInputDialog("用户名:吴泽祥");
    		}});
        
        phoneerBtn =new JButton("手机登录");
        no.add(phoneerBtn);
        
        
        
        phoneerBtn.addActionListener(new ActionListener(){
    
    		@Override
    		public void actionPerformed(ActionEvent arg0) {
    			// TODO Auto-generated method stub
    			String inputValue = JOptionPane.showInputDialog("手机号:");
    		}});    
        frame.pack();
        frame.setVisible(true);		
    }
    private void makeMenuBar() {
    	JMenuBar jmbar =new JMenuBar();
        frame.setJMenuBar(jmbar);
        
    	JMenu themeMenu = new JMenu("主题");
    	JMenu helpMenu = new JMenu("帮助");
    	JMenuItem dayItem = new JMenuItem("day");
    	JMenuItem nightItem = new JMenuItem("night");
    	JMenuItem welcomeItem = new JMenuItem("welcome");
    	themeMenu.add(dayItem);
    	themeMenu.add(nightItem);
    	helpMenu.add(welcomeItem);		
    	jmbar.add(themeMenu);
    	jmbar.add(helpMenu);	
    	
    	
    
    	// TODO Auto-generated method stub
    	 frame.pack();
         
            // place the frame at the center of the screen and show
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            
            frame.setLocation(d.width/2 - frame.getWidth()/2, d.height/2 - frame.getHeight()/2);
          
            frame.setVisible(true);
               
            
    }
    
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
    

    new app();
    }

    }

    package 某聊;

    import javax.swing.JButton;
    import javax.swing.JComboBox;

    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPasswordField;

    public class applogin1 {
    public static void main(String[] args) {
    //创建界面
    final JFrame frm = new JFrame("账户登录");
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setLayout(null);

    JLabel label1 = new JLabel("登录账户:");
    label1.setBounds(50, 40, 120, 25);
    JLabel label2 = new JLabel("密 码:");
    label2.setBounds(50, 80, 120, 25);
    frm.add(label1);
    frm.add(label2);

    //组合框
    JComboBox text = new JComboBox();
    text.setBounds(120, 40, 150, 25);
    text.addItem("1");
    text.addItem("2");
    text.addItem("3");
    text.addItem("4");
    text.setEditable(true);
    //组合框可编辑
    JPasswordField password = new JPasswordField("");
    password.setBounds(120, 80, 150, 25);   
    frm.add(text);
    frm.add(password);
    
    //创建按钮
    JButton yes = new JButton("确定");
    yes.setBounds(90, 150, 95,25);
    
    JButton out = new JButton("退出");
    out.setBounds(190, 150, 95, 25);
    
    frm.add(yes);
    frm.add(out);
    
    frm.pack();
    
    
    frm.setBounds(600,300,400,240);
    frm.setVisible(true);
    

    }

    }
    

    package 某聊;

    import javax.swing.JButton;
    import javax.swing.JComboBox;

    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPasswordField;

    public class applogin2{
    public static void main(String[] args) {
    //创建界面
    final JFrame frm = new JFrame("手机登录");
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setLayout(null);

    JLabel label1 = new JLabel("手机号:");
    label1.setBounds(50, 40, 120, 25);
    JLabel label2 = new JLabel("验证码:");
    label2.setBounds(50, 80, 120, 25);
    frm.add(label1);
    frm.add(label2);

    //组合框
    JComboBox text = new JComboBox();
    text.setBounds(120, 40, 150, 25);
    text.addItem("1");
    text.addItem("2");
    text.addItem("3");
    text.addItem("4");
    text.setEditable(true);
    //组合框可编辑
    JPasswordField password = new JPasswordField("");
    password.setBounds(120, 80, 150, 25);   
    frm.add(text);
    frm.add(password);
    
    //创建按钮
    JButton yes = new JButton("确定");
    yes.setBounds(90, 150, 95,25);
    
    JButton out = new JButton("退出");
    out.setBounds(190, 150, 95, 25);
    
    frm.add(yes);
    frm.add(out);
    
    frm.pack();
    
    
    frm.setBounds(600,300,400,240);
    frm.setVisible(true);
    

    }

    }
    

  • 相关阅读:
    Codeforces1101G (Zero XOR Subset)-less 【线性基】【贪心】
    Codeforces1101F Trucks and Cities 【滑动窗口】【区间DP】
    HDU4651 Partition 【多项式求逆】
    BZOJ2554 color 【概率DP】【期望DP】
    codeforces1101D GCD Counting 【树形DP】
    codechef EBAIT Election Bait【欧几里得算法】
    BZOJ2434 [NOI2011] 阿狸的打字机 【树链剖分】【线段树】【fail树】【AC自动机】
    codeforces1093G Multidimensional Queries 【线段树】
    BZOJ3277 串 【后缀数组】【二分答案】【主席树】
    AHOI2013 差异 【后缀数组】
  • 原文地址:https://www.cnblogs.com/wuzexiang/p/5293287.html
Copyright © 2011-2022 走看看