Java登入介面

來源:互聯網
上載者:User
package test;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import javax.swing.border.EmptyBorder;/** * Java登入介面 * @author JavaApha * 2013年1月25日15:41:38 */public class LoginFrame extends JFrame {private static final long serialVersionUID = 1L;JTextField jtf1;JTextField jtf2;public LoginFrame() {init();}private void init() {setTitle("Java登入頁面");setLocation(300, 200);setSize(300, 200); // 設定內容面板setContentPane(createContentPane());}private JPanel createContentPane() {JPanel pane = new JPanel(new BorderLayout(0, 8));pane.setBorder(new EmptyBorder(12, 12, 12, 12));pane.add(BorderLayout.NORTH, new JLabel("", JLabel.CENTER));pane.add(BorderLayout.CENTER, createNamePwdPane());pane.add(BorderLayout.SOUTH, createBtnPane());return pane;}private JPanel createNamePwdPane() {JPanel pane = new JPanel(new BorderLayout());JPanel top = new JPanel(new GridLayout(2, 1, 0, 6));pane.add(BorderLayout.NORTH, top);top.add(createNamePane());top.add(createPwdPane());return pane;}private JPanel createNamePane() {JPanel pane = new JPanel(new BorderLayout(4, 0));pane.add(BorderLayout.WEST, new JLabel("使用者名稱:"));jtf1 = new JTextField();pane.add(BorderLayout.CENTER, jtf1);return pane;}private JPanel createPwdPane() {JPanel pane = new JPanel(new BorderLayout(4, 0));pane.add(BorderLayout.WEST, new JLabel("密     碼:"));jtf2 = new JPasswordField();pane.add(BorderLayout.CENTER, jtf2);return pane;}private JPanel createBtnPane() {JPanel pane = new JPanel(new FlowLayout());JButton login = new JButton("登入");login.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (jtf2.getText().equals("123")&& jtf1.getText().equals("123")) {System.out.println("登入 ");} else {System.out.println("登入失敗");}}});JButton cancel = new JButton("退出");cancel.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {System.exit(0);}});pane.add(login);pane.add(cancel);return pane;}public void showView() {setVisible(true);}public static void main(String[] args) {LoginFrame lf = new LoginFrame();lf.showView();}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.