当前位置:懂科普 >

综合知识

> java界面怎么写的

java界面怎么写的

1. 怎么用java写一个界面怎么用java写一个界面

新建一个窗口,然后实现一个关闭按钮”窗口的功能

java界面怎么写的

import java.awt.*;

import java.awt.event.*;

public class TestWindowEvent {

public static void main (String[] args) {

new Frame88 ("WindowAdapter");

}

}

class Frame88 extends Frame {

Frame88 (String s) {

super(s);

setBounds (300,300,200,70);

setLayout (null);

setVisible (true);

addWindowListener (new WindowAdapter() {

public void windowClosing(WindowEvent e) {

setVisible (false);

System.exit(0);

}

} );

}

}

2. 用java给一个系统写界面应该怎么写

简单例子可供参考:

import java.awt.*;

import javax.swing.*;

class text2 {

public static void main(String[] args) {

JTextField Name,Number,Class;

JFrame j = new JFrame();

j.setBounds(500, 300, 0, 0);

j.setTitle("Information");

JPanel jp = new JPanel();

jp.setLayout(new GridLayout(4, 1));

final JLabel label_1 = new JLabel();

label_1.setText("Name:");

jp.add(label_1);

Name = new JTextField();

jp.add(Name);

final JLabel label_2 = new JLabel();

label_2.setText("Number:");

jp.add(label_2);

Number = new JTextField();

jp.add(Number);

final JLabel label_3 = new JLabel();

label_3.setText("Class:");

jp.add(label_3);

Class = new JTextField();

jp.add(Class);

final JButton save = new JButton();

jp.add(save);

save.setText("确认");

j.add(jp);

j.pack();

j.setVisible(true);

j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

3. 登陆界面的java代码怎么写

原发布者:梦妙奇缘

用户登录的代码://LoginFrame.javaimportjavax.swing.*;importjava.awt.*;importjava.awt.event.*;classMyJPanelextendsJPanelimplementsActionListener{privateintcount=0;privateJLabellabel1,label2;privateJTextFieldtext;privateJPasswordFieldpass;privateJButtonbutton1,button2;MyJPanel(){label1=newJLabel("用户名");label2=newJLabel("密码");button1=newJButton("确定");button2=newJButton("取消");text=newJTextField(20);pass=newJPasswordField(20);button1.setMnemonic(KeyEvent.VK_O);//设置按钮快捷键button2.setMnemonic(KeyEvent.VK_C);button1.setActionCommand("entry");button2.setActionCommand("cancel");button1.addActionListener(this);//注册按钮事件button2.addActionListener(this);//注册按钮事件setBackground(Color.cyan);//设定面板背景色add(label1);add(text);add(label2);add(pass);add(button1);add(button2);}publicvoidactionPerformed(ActionEvente){if(e.getActionCommand().equals("entry")){count++;//计数Stringusername,password;if(count<3){

4. java写一个登录界面

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

class login extends JFrame implements ActionListener

{

public JPasswordField password;

public JTextField name;

JButton ok;

login()

{

setSize(300,200);//大小

setLocation(200,100);

JPanel panel = new JPanel();//创建一个面板对象

panel.setLayout(new GridBagLayout());

Container cn = this.getContentPane();

GridBagConstraints c = new GridBagConstraints();

c.insets = new Insets(5,2,5,5);

c.gridheight = 1;

JLabel user = new JLabel("User:");

c.gridx = 1;

c.gridy = 1;

panel.add(user,c);

name = new JTextField(10);

c.gridx = 2;

panel.add(name,c);

JLabel pass = new JLabel("assword:");

c.gridx = 1;

c.gridy = 2;

panel.add(pass,c);

password = new JPasswordField(10);

c.gridx = 2;

c.gridy = 2;

panel.add(password,c);

c.gridx = 1;

c.gridy = 3;

ok = new JButton("login");

ok.addActionListener(this);

panel.add(ok,c);

cn.add(panel);

}

public void actionPerformed(ActionEvent e)

{

Object source = e.getSource();

if(source == ok)

{

String username = this.name.getText();

String password = this.password.getText();

String message = username + " "+password;

try

{

byte[] b = message.getBytes();

FileOutputStream fos = new FileOutputStream("login.txt");

fos.write(b,0,b.length);

this.dispose();

}catch(Exception ex)

{

}

}

}

public static void main(String args[])

{

new login().show();

}

}

5. 用Java怎么写一个简单完整的登陆界面

package com.oristand.cn;

import java.awt.GridLayout;

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 QQlogin extends JFrame{

public QQlogin()

{

JFrame jf= new JFrame("QQ登陆界面");

jf.setLayout(new GridLayout(5,1,5,5));

JPanel jp=new JPanel();

JLabel jl=new JLabel("欢迎登陆");

jp.add(jl);

jf.add(jp);

JPanel jp1=new JPanel();

JLabel jl1=new JLabel("用户名");

JTextField jt=new JTextField(10);

jp1.add(jl1);

jp1.add(jt);

jf.add(jp1);

JPanel jp2=new JPanel();

JLabel jl2=new JLabel("密码");

JTextField jt1=new JPasswordField(10);

jp2.add(jl2);

jp2.add(jt1);

jf.add(jp2);

JPanel jp3=new JPanel();

JButton jb=new JButton("登陆");

JButton jb1=new JButton("注册");

JButton jb2=new JButton("设置");

jp3.add(jb);

jp3.add(jb1);

jp3.add(jb2);

jf.add(jp3);

JLabel jl3=new JLabel();

jf.add(jl3);

jf.setSize(300,400);

jf.setVisible(true);

jf.setResizable(false);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args)

{

new QQlogin();

}

}

6. JAVA的界面怎么做

它以抽象窗口工具包(AWT)为基础使跨平台应用程序可以使用任何可插拔的外观风格。Swing开发人员只用很少的代码就可以利用Swing丰富、灵活的功能和模块化组件来创建优雅的用户界面。

工具包中所有的包都是以swing作为名称,例如javax.swing,javax.swing.event

用Swing创建图形界面步骤:

(1)导入Swing包

(2)选择界面风格

(3)设置顶层容器

(4)设置按钮和标签

(5)将组件放到容器上

(6)为组件增加边框

(8)辅助技术支持

7. 编写一个Java的界面设计程序

import java.awt.BorderLayout; import java.awt.event.*;import javax.swing.*;import java.awt.*;public class Moble extends JFrame { private JTextField txtView; public static void main(String args[]) { try { Moble moble = new Moble(); moble.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } public Moble() { setTitle("模拟手机"); setBounds(100, 100, 200, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); final JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.CENTER); txtView = new JTextField(); panel.setLayout(null); panel.add(txtView); final JButton btn1 = new JButton(); btn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { txtView.setText(txtView.getText().concat("1")); } }); btn1.setText("1"); btn1.setBounds(0, 73, 59, 23); panel.add(btn1); JButton btn2 = new JButton(); btn2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { txtView.setText(txtView.getText().concat("2")); } }); btn2.setText("2"); btn2.setBounds(68, 73, 59, 23); panel.add(btn2); JButton btn3 = new JButton(); btn3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { txtView.setText(txtView.getText().concat("3")); } }); btn3.setText("3"); btn3.setBounds(133, 73, 59, 23); panel.add(btn3); JButton btn4 = new JButton(); btn4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { txtView.setText(txtView.getText().concat("4")); } }); btn4.setText("4"); btn4.setBounds(0, 102, 59, 23); panel.add(btn4); JButton btn5 = new JButton(); btn5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { txtView.setText(txtView.getText().concat("5")); } }); btn5.setText("5"); btn5.setBounds(65, 102, 59, 23); panel.add(btn5); JButton btn6 = new JButton(); btn6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { txtView.setText(txtView.getText().concat("6")); } }); btn6.setText("6"); btn6.setBounds(133, 102, 59, 23); panel.add(btn6); JButton b1 = new JButton(); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { txtView.setText(txtView.getText().concat("*")); } }); b1.setText("*"); b1.setBounds(0, 160, 59, 23); panel.add(b1); JButton b2 = new JButton(); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { txtView.setText(txtView.getText().concat("#")); } }); b2.setText("#"); b2.setBounds(133, 160, 59, 23); panel.add(b2); JButton btn7 = new JButton(); btn7.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { txtView.setText(txtView.getText().concat("7")); } }); btn7.setText("7"); btn7.setBounds(0, 131, 59, 23); panel.add(btn7); JButton btn8 = new JButton(); btn8.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { txtView.setText(txtView.getText().concat("8")); } }); btn8.setText("8"); btn8.setBounds(65, 131, 59, 23); panel.add(btn8); JButton btn9 = new JButton(); btn9.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { txtView.setText(txtView.getText().concat("9")); } }); btn9.setText("9"); btn9.setBounds(133, 131, 59, 23); panel.add(btn9); JButton btn0 = new JButton(); btn0.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { txtView.setText(txtView.getText().concat("0")); } }); btn0.setText("0"); btn0.setBounds(68, 160, 57, 23); panel.add(btn0); txtView = new JTextField(); txtView.setBounds(20, 24, 170, 21); panel.add(txtView); final JButton btnSend = new JButton(); btnSend.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(txtView.getText().length()>3||txtView.getText().length() 评论0 0 0。

8. java如何写这个图形界面

//自己在微调一下坐标吧..import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.Rectangle;import java.io.Serializable;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public class SwingTest extends JFrame implements Serializable{ private JPanel jp1,jp2,jp3; private JLabel ab1; private But[] list=But.values(); private static final long serialVersionUID = 1L; SwingTest(){ this.setTitle("系统首页"); this.setBounds(300, 300, 280, 200); this.setResizable(false); init(); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setVisible(true); } private void init() { jp1=new JPanel(); jp1.add(new JLabel("欢迎你来到图书馆租借系统")); jp2=new JPanel(null); ab1=new JLabel("请选择服务项目"); ab1.setBounds(new Rectangle(0, 0, 220, 25)); jp2.add(ab1); jp3=new JPanel(new GridLayout(6,1)); jp3.setBounds(80, 20, 120, 120); for (int i = 0; i jp3.add(new JButton(list[i].toString())); } jp2.add(jp3); this.add(jp1,BorderLayout.NORTH); this.add(jp2,BorderLayout.CENTER); } public static void main(String[] args) { new SwingTest(); } enum But{ 馆藏查询,节约查询,欠费查询,借书登记,还书登记,退出系统; }}。

9. 如何用JAVA编程编写一个界面程序(急求

我下面写了一个,初始账号和密码是 nihao 5201314 你可以改或设置

import java.awt.*;

import java.awt.event.*;

class MyDow extends Frame implements ActionListener{

private Label lName,lPassword;

private TextField tName,tPassword;

private Button login,rest,exitout;

private Label login_clew;

private int count=0;

private String myName="nihao";

private String myPassword="5201314";

public void setMyNP(String n,String p){

myName=n;

myPassword=p;

}

public MyDow(String str){

super(str);

}

public void init(){

setLayout(null);

setSize(400,300);

setVisible(true);

setResizable(false);

lName=new Label("姓名");

lName.setBounds(50, 70, 60, 30);add(lName);

lPassword=new Label("密码");

lPassword.setBounds(50, 120, 60, 30);add(lPassword);

tName=new TextField("");

tName.setBounds(110, 70, 200, 30);add(tName);

tPassword=new TextField("");

tPassword.setBounds(110, 120, 200, 30);add(tPassword);

login=new Button("登录");

login.setBounds(90, 200, 60, 30);add(login);

rest=new Button("重输");

rest.setBounds(170, 200, 60, 30);add(rest);

exitout=new Button("退出");

exitout.setBounds(250,200,60,30);add(exitout);

login_clew=new Label("");

login.addActionListener(this);

rest.addActionListener(this);

exitout.addActionListener(this);

}

public void actionPerformed(ActionEvent e){

if(e.getSource()==login){

if(count

标签: java 界面
  • 文章版权属于文章作者所有,转载请注明 https://dongkepu.com/zonghezhishi/jpol9g.html