「java界面程序」java程序界面是什么写的

博主:adminadmin 2022-12-17 11:27:08 92

今天给各位分享java界面程序的知识,其中也会对java程序界面是什么写的进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Java编写图形用户界面程序

运行如图

参考代码如下

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class RegDemo extends JFrame implements ActionListener{

JTextField jtf;

JPasswordField jpf;

public RegDemo() {

        //组件的创建, 和布局安排

JPanel jpc = new JPanel();//默认流式布局

JPanel jp1 = new JPanel(new GridLayout(2, 2,5,10));//网格布局

jp1.setBorder(BorderFactory.createTitledBorder("用户注册"));

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

jtf = new JTextField(10);

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

jpf = new JPasswordField(10);

                jpf.setEchoChar('*');//用*号来隐藏密码的显示

jp1.add(jl1);jp1.add(jtf);

jp1.add(jl2);jp1.add(jpf);

jpc.add(jp1);

add(jpc);

JButton jb1 = new JButton("提交");

jb1.addActionListener(this);

jb1.setActionCommand("yes");

JButton jb2 = new JButton("取消");

jb2.addActionListener(this);

jb2.setActionCommand("no");

JPanel jp2 = new JPanel();

jp2.add(jb1);jp2.add(jb2);

add(jp2,BorderLayout.SOUTH);

setTitle("用户注册界面");

        setSize(280, 280);

        setLocationRelativeTo(null);//窗口居中

        setDefaultCloseOperation(EXIT_ON_CLOSE);//

        setVisible(true);

}

public static void main(String[] args) {

new RegDemo();

}

@Override

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand().equals("yes")){

String name  = jtf.getText().trim();

String pwd = new String(jpf.getPassword());

if(name.equals("")||pwd.equals("")){

JOptionPane.showMessageDialog(this, "你还没有输入用户名或者密码");

}else{

JOptionPane.showMessageDialog(this, "注册成功!用户名"+name+",密码"+pwd);

}

}else{

jtf.setText("");

jpf.setText("");

}

}

}

如何用JAVA编写应用界面程序(用myeclipse)

package gui.test;//包名

import javax.swing.JFrame;//导入需要的窗口包JFrame

import javax.swing.JLabel;//导入需要的标签包JLabel

public class MainFrame extends JFrame{

//构造方法进行初始化窗口

public MainFrame(){

JLabel jl = new JLabel();//创建一个标签

jl.setText("Hello World");//标签上的文字叫Hello World

//下面的this都指的是本窗口.都可以省略

this.add(jl);//窗口添加刚刚创建的标签

this.setTitle("窗口标题");//窗口的标题名字

this.setLocation(300, 200);//窗口的左顶点在屏幕上的位置

this.setSize(200, 220);//窗口是 宽200像素, 长220像素

this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口被关闭时候就退出窗口

this.setVisible(true);//设置这个窗口能否被看见

}

public static void main(String[] args) {

new MainFrame();//调用构造方法,创建一个窗口

}

}

JAVA 用什么做界面程序

Swing是一个用于开发Java应用程序用户界面的开发工具包。

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

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

JAVA图形界面程序编写

我真的是抽风了,手痒了,给你写了这段代码,如果楼主、、、

嘻嘻,追点分给我吧

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import javax.swing.*;

public class baidu_9 extends JFrame implements ActionListener

{

static final String OUTPUT="C://Test.txt";

JPanel pnl;

JLabel lbl;

JTextField txt1,txt2;

JButton btnCopy,btnClear,btnOutput,btnColor;

public baidu_9()

{

super("百度题目");

pnl=new JPanel();

this.setContentPane(pnl);

pnl.setLayout(null);

pnl.setBackground(Color.WHITE);

lbl=new JLabel("百度");

txt1=new JTextField(10);

txt2=new JTextField(10);

btnCopy=new JButton("复制");

btnCopy.addActionListener(this);

btnClear=new JButton("清除");

btnClear.addActionListener(this);

btnOutput=new JButton("写入");

btnOutput.addActionListener(this);

btnColor=new JButton("变色");

btnColor.addActionListener(this);

lbl.setBounds(100, 10, 80, 20);

txt1.setBounds(10, 40, 100, 20);

txt2.setBounds(120, 40, 100, 20);

btnCopy.setBounds(10, 70, 60, 20);

btnClear.setBounds(75, 70, 60, 20);

btnOutput.setBounds(140, 70, 60, 20);

btnColor.setBounds(205, 70, 60, 20);

pnl.add(lbl);

pnl.add(txt1);

pnl.add(txt2);

pnl.add(btnCopy);

pnl.add(btnClear);

pnl.add(btnOutput);

pnl.add(btnColor);

setSize(300,150);

setVisible(true);

}

public void Copy()

{

txt2.setText(txt1.getText());

}

public void Clear()

{

txt1.setText("");

txt2.setText("");

pnl.setBackground(Color.WHITE);

}

public void Color()

{

pnl.setBackground(Color.BLACK);

}

public void Ouput()

{

try

{

File fl=new File("C:\\Test.txt");

FileWriter fw = new FileWriter(fl);

BufferedWriter bw = new BufferedWriter(fw);

bw.write(txt1.getText());

bw.close();

}

catch (IOException e)

{

e.printStackTrace();

}

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==btnCopy)

this.Copy();

if(e.getSource()==btnClear)

this.Clear();

if(e.getSource()==btnColor)

this.Color();

if(e.getSource()==btnOutput)

this.Ouput();

}

public static void main(String[] args)

{

new baidu_9();

}

}

java界面程序的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java程序界面是什么写的、java界面程序的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-17,除非注明,否则均为首码项目网原创文章,转载请注明出处。