导航:首页 > 编程语言 > java写页面

java写页面

发布时间:2023-09-19 18:22:01

1. 如何用java编写一个简单用户登陆界面

什么都不说了 直接给你代码吧x0dx0apackage com.moliying.ui;x0dx0aimport java.awt.BorderLayout;x0dx0aimport java.awt.Container;x0dx0aimport java.awt.FlowLayout;x0dx0aimport java.awt.List;x0dx0aimport java.awt.event.ActionEvent;x0dx0aimport java.awt.event.ActionListener;x0dx0aimport java.io.BufferedWriter;x0dx0aimport java.io.FileOutputStream;x0dx0aimport java.io.OutputStreamWriter;x0dx0aimport java.util.ArrayList;x0dx0aimport java.util.Arrays;x0dx0aimport javax.swing.JButton;x0dx0aimport javax.swing.JFrame;x0dx0aimport javax.swing.JLabel;x0dx0aimport javax.swing.JPanel;x0dx0aimport javax.swing.JPasswordField;x0dx0aimport javax.swing.JTextField;x0dx0apublic class Login {x0dx0aprivate JFrame frame = new JFrame("登录");x0dx0aprivate Container c = frame.getContentPane();x0dx0aprivate JTextField username = new JTextField();x0dx0aprivate JPasswordField password = new JPasswordField();x0dx0aprivate JButton ok = new JButton("确定");x0dx0aprivate JButton cancel = new JButton("取消");x0dx0apublic Login() {x0dx0aframe.setSize(300, 200);x0dx0aframe.setBounds(450, 300, 300, 200);x0dx0ac.setLayout(new BorderLayout());x0dx0ainitFrame();x0dx0aframe.setVisible(true);x0dx0a}x0dx0aprivate void initFrame() {x0dx0a// 顶部x0dx0aJPanel titlePanel = new JPanel();x0dx0atitlePanel.setLayout(new FlowLayout());x0dx0atitlePanel.add(new JLabel("系统管理员登录"));x0dx0ac.add(titlePanel, "North");x0dx0a// 中部表单x0dx0aJPanel fieldPanel = new JPanel();x0dx0afieldPanel.setLayout(null);x0dx0aJLabel a1 = new JLabel("用户名:");x0dx0aa1.setBounds(50, 20, 50, 20);x0dx0aJLabel a2 = new JLabel("密 码:");x0dx0aa2.setBounds(50, 60, 50, 20);x0dx0afieldPanel.add(a1);x0dx0afieldPanel.add(a2);x0dx0ausername.setBounds(110, 20, 120, 20);x0dx0apassword.setBounds(110, 60, 120, 20);x0dx0afieldPanel.add(username);x0dx0afieldPanel.add(password);x0dx0ac.add(fieldPanel, "Center");x0dx0a// 底部按钮x0dx0aJPanel buttonPanel = new JPanel();x0dx0abuttonPanel.setLayout(new FlowLayout());x0dx0abuttonPanel.add(ok);x0dx0abuttonPanel.add(cancel);x0dx0ac.add(buttonPanel, "South");x0dx0ax0dx0aok.addActionListener(new ActionListener() {x0dx0ax0dx0a@Overridex0dx0apublic void actionPerformed(ActionEvent e) {x0dx0aSystem.out.println(username.getText().toString());x0dx0a}x0dx0a});x0dx0ax0dx0acancel.addActionListener(new ActionListener() {x0dx0ax0dx0a@Overridex0dx0apublic void actionPerformed(ActionEvent e) {x0dx0aframe.setVisible(false);x0dx0a}x0dx0a});x0dx0a}x0dx0apublic static void main(String[] args) {x0dx0a//new Login();x0dx0ax0dx0aString ss = "abbabbbaabbbccba";x0dx0ax0dx0aSystem.out.println(ss.split("b").length);x0dx0ax0dx0a}x0dx0a}

2. 如何用java制作网页

怎么用java来编写网页,目前比较流行的是SSH(struts2+spring+hibernate)框架。其实只要有servlet和JSP基础就可以实现,框架只是高效的开发和管理。
推荐使用SSH框架进行开发。
使用struts2来实现页面跳转,他的标签也可以写JSP界面。
使用hibernate来进行数据库操作的封装,进行自动管理。
使用spring可以整合以上两个,使控制权转移给spring,这个就是控制反转。
具体页面怎么写,这个多看下工具书不难。前台页面可以使用HTML来写,解析速度快,并且页面开发难度低,排版效果好。

3. 怎么用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);
}
} );
}
}

4. 怎样用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。

5. 用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);

}

}

6. java编写一个图形界面程序

importjava.awt.*;
importjava.awt.event.*;
importjava.util.*;
importjavax.swing.*;
importjavax.swing.border.Border;


classMainFrameextendsJFrame{

=1L;

privateMap<String,Integer>sizes=newHashMap<String,Integer>();

privateMap<String,Integer>styles=newHashMap<String,Integer>();

privateMap<String,Integer>toppings=newHashMap<String,Integer>();

publicMainFrame(){

sizes.put("ExtraLarge",10);
sizes.put("Large",8);
sizes.put("Medium",5);
sizes.put("Small",3);

styles.put("DeepDish",20);
styles.put("Regular",10);
styles.put("ThinCrust",5);
styles.put("Chicago",3);

toppings.put("Cheese",8);
toppings.put("Tomato",7);
toppings.put("Peppers",6);
toppings.put("Peperoni",5);

this.setTitle("布局及事件处理");
this.setSize(450,350);
this.setLayout(newBorderLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabellblTitle=newJLabel();
lblTitle.setText("PizzeriaJuno");
lblTitle.setFont(newFont("宋体",Font.BOLD,36));
lblTitle.setHorizontalAlignment(SwingConstants.CENTER);
this.add("North",lblTitle);

JPanelbodyPanel=newJPanel();
bodyPanel.setLayout(newGridLayout(2,1));
this.add("Center",bodyPanel);

JPanellistPanel=newJPanel();
listPanel.setLayout(newGridLayout(1,3));
listPanel.setSize(200,200);
bodyPanel.add(listPanel);

BorderlineBorder=BorderFactory.createLineBorder(Color.BLACK);

JPanelsizePanel=newJPanel();
sizePanel.setLayout(newBorderLayout());
listPanel.add(sizePanel);
JLabelsizeTitle=newJLabel();
sizeTitle.setText("Sizes");
sizePanel.add("North",sizeTitle);


JListsizeList=newJList(sizes.keySet().toArray());
sizeList.setSize(100,100);
sizeList.setBorder(lineBorder);
sizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
sizePanel.add(sizeList);

JPanelstylePanel=newJPanel();
stylePanel.setLayout(newBorderLayout());
listPanel.add(stylePanel);
JLabelstyleTitle=newJLabel();
styleTitle.setText("Styles");
stylePanel.add("North",styleTitle);
JListstyleList=newJList(styles.keySet().toArray());
styleList.setSize(100,100);
styleList.setBorder(lineBorder);
styleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
stylePanel.add(styleList);

JPaneltoppingPanel=newJPanel();
toppingPanel.setLayout(newBorderLayout());
listPanel.add(toppingPanel);
JLabeltoppingTitle=newJLabel();
toppingTitle.setText("Toppings");
toppingPanel.add("North",toppingTitle);
JListtoppingList=newJList(toppings.keySet().toArray());
toppingList.setSize(100,100);
toppingList.setBorder(lineBorder);
toppingPanel.add(toppingList);

JTextAreatxtResult=newJTextArea();
txtResult.setEditable(false);
bodyPanel.add(txtResult);

JPanelbottomPanel=newJPanel();
bottomPanel.setLayout(newGridLayout(1,3));
this.add("South",bottomPanel);

JLabellabel1=newJLabel("Clicktocompleteorder");
bottomPanel.add(label1);

JButtonbtnRingUp=newJButton("Ringup");
btnRingUp.addActionListener(newActionListener(){

@Override
publicvoidactionPerformed(ActionEvente){



if(sizeList.getSelectedValue()==null){
JOptionPane.showMessageDialog(MainFrame.this,"Pleaseselectsize.");
return;
}

if(styleList.getSelectedValue()==null){
JOptionPane.showMessageDialog(MainFrame.this,"Pleaseselectstyle.");
return;
}

if(toppingList.getSelectedValue()==null){
JOptionPane.showMessageDialog(MainFrame.this,"Pleaseselecttopping.");
return;
}

floattotal=0;

Stringsize=sizeList.getSelectedValue().toString();
total+=sizes.get(size);

Stringstyle=styleList.getSelectedValue().toString();
total+=styles.get(style);

Stringresult=size+"Pizza,"+style+"Style";

Object[]toppings=toppingList.getSelectedValues();
for(Objecttopping:toppings){
result+=" +"+topping.toString();
total+=MainFrame.this.toppings.get(topping.toString());
}

result+=" Total:"+total;

txtResult.setText(result);
}
});
bottomPanel.add(btnRingUp);

JButtonbtnQuit=newJButton("Quit");
btnQuit.addActionListener(newActionListener(){

@Override
publicvoidactionPerformed(ActionEvente){
MainFrame.this.dispose();
}
});
bottomPanel.add(btnQuit);
}

}

publicclassApp{

publicstaticvoidmain(String[]args){


MainFramemainFrame=newMainFrame();
mainFrame.setVisible(true);

}

}

阅读全文

与java写页面相关的资料

热点内容
不玩手机APP怎么开启警报 浏览:558
打开微信收付款加密 浏览:400
小度app怎么关闭看护助手 浏览:739
服务器方舟boss属性怎么调 浏览:345
acos系统终端命令 浏览:915
宁德云服务器最新行情 浏览:475
压缩性骨折五十天 浏览:656
如何在服务器里把方块替换 浏览:909
变频空调摘板用什么替代压缩机 浏览:46
怎么在苹果手机上玩安卓和平精英 浏览:237
python异步调用框架 浏览:963
安卓手机如何拍live图 浏览:823
供应链管理系统源码 浏览:944
方舟编译器会适配哪些型号 浏览:470
主流云服务器哪个牌子好 浏览:267
导航怎么看服务器在那 浏览:932
广石化单片机 浏览:281
和教育连接服务器失败是什么原因 浏览:1003
建行app怎么存定期 浏览:830
mc服务器地址183 浏览:73