導航:首頁 > 編程語言 > 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寫頁面相關的資料

熱點內容
outlook命令 瀏覽:229
程序員那麼可愛主角介紹 瀏覽:932
銀行卡簡訊消息如何加密 瀏覽:246
文件夾怎麼不重名 瀏覽:406
linuxyum安裝java 瀏覽:250
java數字計算 瀏覽:286
java按鈕文字 瀏覽:641
python列表互換位置 瀏覽:337
sw怎麼刪除定向命令 瀏覽:757
php包含數組元素 瀏覽:666
安卓系統開發app需要什麼 瀏覽:730
ssh2項目源碼 瀏覽:288
三星提供了什麼伺服器地址 瀏覽:903
阿里雲輕量應用伺服器60元 瀏覽:160
微信公眾號支付java 瀏覽:217
蝦皮用的什麼伺服器 瀏覽:144
拍照的app哪個好用 瀏覽:890
方舟編譯器2022 瀏覽:770
一般情況下源碼注釋量 瀏覽:743
18號命令 瀏覽:871