您的位置:

java中的gui入门,java的GUI是什么

本文目录一览:

如何快速掌握Java GUI设计

使用java的GUI设计一个简单的登陆界面(1)

实现效果如下:

源代码:

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.FlowLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

public class Login{

private JFrame frame = new JFrame("登录");

private Container c = frame.getContentPane();

private JTextField username = new JTextField();

private JPasswordField password = new JPasswordField();

private JButton ok = new JButton("确定");

private JButton cancel = new JButton("取消");

public Login(){

frame.setSize(300,200);

c.setLayout(new BorderLayout());

initFrame();

frame.setVisible(true);

}

private void initFrame(){

//顶部

JPanel titlePanel = new JPanel();

titlePanel.setLayout(new FlowLayout());

titlePanel.add(new JLabel("系统管理员登录"));

c.add(titlePanel,"North");

//中部表单

JPanel fieldPanel = new JPanel();

fieldPanel.setLayout(null);

JLabel a1 = new JLabel("用户名:");

a1.setBounds(50,20,50,20);

JLabel a2 = new JLabel("密 码:");

a2.setBounds(50,60,50,20);

fieldPanel.add(a1);

fieldPanel.add(a2);

username.setBounds(110,20,120,20);

password.setBounds(110,60,120,20);

fieldPanel.add(username);

fieldPanel.add(password);

c.add(fieldPanel,"Center");

//底部按钮

JPanel buttonPanel = new JPanel();

buttonPanel.setLayout(new FlowLayout());

buttonPanel.add(ok);

buttonPanel.add(cancel);

c.add(buttonPanel,"South");

}

public static void main(String[] args){

new Login();

}

}

给个java GUI 基础教程吧

package com.ambow.sky;

import java.awt.BorderLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class TestBorderLayout extends JFrame {

JPanel jp;

JButton jb1,jb2,jb3,jb4,jb5;

public TestBorderLayout() {

this.setSize(300, 300);

jp = new JPanel();

jp.setLayout(new BorderLayout());

jb1 = new JButton("东部");

jb2 = new JButton("西部");

jb3 = new JButton("南部");

jb4 = new JButton("北部");

jb5 = new JButton("中部");

jp.add(jb1, BorderLayout.EAST);

jp.add(jb2, BorderLayout.WEST);

jp.add(jb3, BorderLayout.SOUTH);

jp.add(jb4, BorderLayout.NORTH);

jp.add(jb5, BorderLayout.CENTER);

this.add(jp);

this.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new TestBorderLayout();

}

}

这是一个布局的GUI,你可以运行看一下!

java中的GUI

其实你也不用严格的按着几步来做:

1,导入包也就是

import java.awt.*;

import java.awt.event.*;

或者import javax.swing.*;

import javax.swing.event.*;

2,构造,估计就是构造方法,就是初始化你的组件,

3,不知道

4,应该是给组件加监视器

5,实现接口的方法,也就是当你按了按钮或选择了菜单项会发生的动作