「java页面程序」网页运行java程序

博主:adminadmin 2022-11-23 20:34:08 61

本篇文章给大家谈谈java页面程序,以及网页运行java程序对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

用java程序编写一个简单的登录界面怎么写?

程序如下:

mport java.awt.HeadlessException;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.ImageIcon;

import javax.swing.JButton;

@SuppressWarnings("serial")

public class MainFrame extends JFrame {

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

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

JTextField txt = new JTextField("admin",20);

JPasswordField pwd = new JPasswordField(20);

JButton btn = new JButton("登录");

JPanel pnl = new JPanel();

private int error = 0;

public MainFrame(String title) throws HeadlessException {

super(title);

init();

}

private void init() {

this.setResizable(false);

pwd.setEchoChar('*');

pnl.add(lbl1);

pnl.add(txt);

btn.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if ("admin".equal花憨羔窖薏忌割媳公颅s(new String(pwd.getPassword()))){

pnl.removeAll();

JLabel lbl3 = new JLabel();

ImageIcon icon = new ImageIcon(this.getClass().getResource("pic.jpg"));

lbl3.setIcon(icon);

pnl.add(lbl3);

}

else{

if(error 3){

JOptionPane.showMessageDialog(null,"密码输入错误,请再试一次");

error++;

}

else{

JOptionPane.showMessageDialog(null,"对不起,您不是合法用户");

txt.setEnabled(false);

pwd.setEnabled(false);

btn.setEnabled(false);

}

}

}

});

}

public static void main(String[] args) {

MainFrame frm = new MainFrame("测试");

frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frm.setBounds(100, 100, 300, 120);

frm.setVisible(true);

}

}

编程的注意事项:

1、Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。

2、 Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等。

3、2006年11月13日,Java技术的发明者Sun公司宣布,将Java技术作为免费软件对外发布。Sun公司正式发布的有关Java平台标准版的第一批源代码,以及Java迷你版的可执行源代码。从2007年3月起,全世界所有的开发人员均可对Java源代码进行修改。

JAVA 用什么做界面程序

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

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

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

怎样用java编写图形界面的Application程序

java编写图形界面需要用到swing等组件,可以在eclipse中安装windowbuilder来开发窗体,自动生成窗体代码,然后自己再根据需要修改,如:

package mainFrame;

import java.awt.EventQueue;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JCheckBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

import javax.swing.SwingConstants;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

import javax.swing.border.EmptyBorder;

public class Mian_login extends JFrame {

private JPanel contentPane;

private JTextField text_LoginName;

private JPasswordField Login_password;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

@Override

public void run() {

try {

Mian_login frame = new Mian_login();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public Mian_login() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(500, 200, 443, 300);

setResizable(false);

setTitle("登 录");

/*获取系统按钮样式*/

String lookAndFeel = UIManager.getSystemLookAndFeelClassName();

try {

UIManager.setLookAndFeel(lookAndFeel);

} catch (ClassNotFoundException e1) {

e1.printStackTrace();

} catch (InstantiationException e1) {

e1.printStackTrace();

} catch (IllegalAccessException e1) {

e1.printStackTrace();

} catch (UnsupportedLookAndFeelException e1) {

e1.printStackTrace();

}

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

contentPane.setLayout(null);

JPanel panel = new JPanel();

panel.setOpaque(false);

panel.setBounds(0, 0, 434, 272);

contentPane.add(panel);

panel.setLayout(null);

JButton btn_Login = new JButton("\u767B\u5F55");

btn_Login.addMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

}

});

btn_Login.setBounds(88, 195, 70, 23);

panel.add(btn_Login);

JButton btn_cancel = new JButton("\u53D6\u6D88");

btn_cancel.addMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

dispose();

}

});

btn_cancel.setBounds(268, 195, 70, 23);

panel.add(btn_cancel);

JLabel lblNewLabel_name = new JLabel("\u7528\u6237\u540D");

lblNewLabel_name.setHorizontalAlignment(SwingConstants.CENTER);

lblNewLabel_name.setOpaque(true);

lblNewLabel_name.setBounds(88, 48, 70, 23);

panel.add(lblNewLabel_name);

JLabel lblNewLabel_passwd = new JLabel("\u5BC6\u7801");

lblNewLabel_passwd.setHorizontalAlignment(SwingConstants.CENTER);

lblNewLabel_passwd.setOpaque(true);

lblNewLabel_passwd.setBounds(88, 102, 70, 23);

panel.add(lblNewLabel_passwd);

JCheckBox chckbx_remember = new JCheckBox("\u8BB0\u4F4F\u5BC6\u7801");

chckbx_remember.setBounds(102, 150, 84, 23);

panel.add(chckbx_remember);

text_LoginName = new JTextField();

text_LoginName.setBounds(182, 48, 156, 23);

panel.add(text_LoginName);

text_LoginName.setColumns(10);

Login_password = new JPasswordField();

Login_password.setBounds(182, 102, 156, 23);

panel.add(Login_password);

JCheckBox chckbx_AutoLogin = new JCheckBox("\u81EA\u52A8\u767B\u5F55");

chckbx_AutoLogin.setBounds(233, 150, 84, 23);

panel.add(chckbx_AutoLogin);

JLabel Label_background = new JLabel("");

Label_background.setIcon(new ImageIcon("E:\\JAVA_workplace\\0002-\u754C\u9762\u8BBE\u8BA1\\images\\background3.jpg"));

Label_background.setBounds(0, 0, 437, 272);

contentPane.add(Label_background);

}

}

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图形界面程序编写

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

嘻嘻,追点分给我吧

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-11-23,除非注明,否则均为首码项目网原创文章,转载请注明出处。