當前位置:首頁 » 軟體設計 » java界面設計

java界面設計

發布時間: 2020-12-04 16:53:09

Ⅰ 用java設計一個簡單的界面設計,越簡單越好,謝謝

用java設計一個簡單的界面可以參考如下實例:

importjavax.swing.JFrame;//框架
importjavax.swing.JPanel;//面板
importjavax.swing.JButton;//按鈕
importjavax.swing.JLabel;//標簽
importjavax.swing.JTextField;//文本框
importjava.awt.Font;//字體
importjava.awt.Color;//顏色
importjavax.swing.JPasswordField;//密碼框
importjava.awt.event.ActionListener;//事件監聽
importjava.awt.event.ActionEvent;//事件處理
importjavax.swing.JOptionPane;//消息窗口{
publicJPanelpnluser;
publicJLabellbluserLogIn;
publicJLabellbluserName;
publicJLabellbluserPWD;
publicJTextFieldtxtName;
publicJPasswordFieldpwdPwd;
publicJButtonbtnSub;
publicJButtonbtnReset;
publicUserLogIn(){
pnluser=newJPanel();
lbluserLogIn=newJLabel();
lbluserName=newJLabel();
lbluserPWD=newJLabel();
txtName=newJTextField();
pwdPwd=newJPasswordField();
btnSub=newJButton();
btnReset=newJButton();
userInit();
}
publicvoiserInit(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設置關閉框架的同時結束程序
this.setSize(300,200);//設置框架大小為長300,寬200
this.setResizable(false);//設置框架不可以改變大小
this.setTitle("用戶登錄");//設置框架標題
this.pnluser.setLayout(null);//設置面板布局管理
this.pnluser.setBackground(Color.cyan);//設置面板背景顏色
this.lbluserLogIn.setText("用戶登錄");//設置標簽標題
this.lbluserLogIn.setFont(newFont("宋體",Font.BOLD|Font.ITALIC,14));//設置標簽字體
this.lbluserLogIn.setForeground(Color.RED);//設置標簽字體顏色
this.lbluserName.setText("用戶名:");
this.lbluserPWD.setText("密碼:");
this.btnSub.setText("登錄");
this.btnReset.setText("重置");
this.lbluserLogIn.setBounds(120,15,60,20);//設置標簽x坐標120,y坐標15,長60,寬20
this.lbluserName.setBounds(50,55,60,20);
this.lbluserPWD.setBounds(50,85,60,25);
this.txtName.setBounds(110,55,120,20);
this.pwdPwd.setBounds(110,85,120,20);
this.btnSub.setBounds(85,120,60,20);
this.btnSub.addActionListener(newActionListener()//匿名類實現ActionListener介面
{
publicvoidactionPerformed(ActionEvente){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(155,120,60,20);
this.btnReset.addActionListener(newActionListener()//匿名類實現ActionListener介面
{
publicvoidactionPerformed(ActionEvente){
btnreset_ActionEvent(e);
}
}
);
this.pnluser.add(lbluserLogIn);//載入標簽到面板
this.pnluser.add(lbluserName);
this.pnluser.add(lbluserPWD);
this.pnluser.add(txtName);
this.pnluser.add(pwdPwd);
this.pnluser.add(btnSub);
this.pnluser.add(btnReset);
this.add(pnluser);//載入面板到框架
this.setVisible(true);//設置框架可顯
}
publicvoidbtnsub_ActionEvent(ActionEvente){
Stringname=txtName.getText();
Stringpwd=String.valueOf(pwdPwd.getPassword());
if(name.equals("")){
JOptionPane.showMessageDialog(null,"賬號不能為空","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}elseif(pwd.equals("")){
JOptionPane.showMessageDialog(null,"密碼不能為空","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}elseif(true){
this.dispose();
}else{
JOptionPane.showMessageDialog(null,"賬號或密碼錯誤","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}
}
publicvoidbtnreset_ActionEvent(ActionEvente){
txtName.setText("");
pwdPwd.setText("");
}
publicstaticvoidmain(String[]args){
newUserLogIn();
}
}

Ⅱ Java 用戶界面設計 求界面代碼

一: 首先弄清題目的意思

A.需要的主要組件列表:

1. 創建一個窗口,窗口標題叫Information

2. 3個標簽, 用於顯示文字 Name Number Class

3. 3個文本框, 用於填寫信息

4. 1個按鈕, 文字是確認

5. 1個文本域

B.業務邏輯

1. 當點擊按鈕確認的時候, 把 文本框的信息顯示到文本域

C.設計的主要技術

JLabel , JButton, JTextField ...等, 都是swing的組件 , 所以應該使用swing進行創建


二: 確定使用的布局

swing雖然重寫了大部分的組件, 但是布局, 依舊沿襲awt技術

分析圖片上的布局:

至少有2種方法可以實現,

方法一: 絕對布局 , 優點: 配合可視化GUI拖曳, 可以完美的實現圖上的組件的位置

但是缺點也是致命的, 不同的操作系統平台下, 可能會出現位置的移動,

只適合開發平台, 移植效果差 . 所以不推薦使用

方法二: 靈活的表格布局, 配合流式布局 , 所有操作系統下,顯示效果都比較統一.


三: 效果圖


importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;

{
//申明需要的組件
privatefinalJTextFieldjtf1,jtf2,jtf3;
privatefinalJTextAreajta;

publicFrameDemo(){
setTitle("Information");//設置窗口標題
setSize(320,360);//設置窗口大小
setLocationRelativeTo(null);//設置窗口居中
setDefaultCloseOperation(EXIT_ON_CLOSE);//設置關閉時退出虛擬機
getContentPane().setLayout(newFlowLayout());//設置窗口布局為流式布局
JPaneljp=newJPanel(newGridLayout(4,2));//設置jp面板為表格布局4行2列
//第一行
JPaneljp01=newJPanel();
JLabeljl1=newJLabel("Name:");
jp01.add(jl1);
JPaneljp1=newJPanel();
jtf1=newJTextField(8);
jp1.add(jtf1);
//第二行
JPaneljp02=newJPanel();
JLabeljl2=newJLabel("Number:");
jp02.add(jl2);
JPaneljp2=newJPanel();
jtf2=newJTextField(8);
jp2.add(jtf2);
//第三行
JPaneljp03=newJPanel();
JLabeljl3=newJLabel("Class:");
jp03.add(jl3);
JPaneljp3=newJPanel();
jtf3=newJTextField(8);
jp3.add(jtf3);
//第四行
JPaneljp04=newJPanel();
JLabeljl4=newJLabel("");
jp04.add(jl4);
JPaneljp4=newJPanel();
JButtonjb=newJButton("確認");
jp4.add(jb);

jp.add(jp01);
jp.add(jp1);
jp.add(jp02);
jp.add(jp2);
jp.add(jp03);
jp.add(jp3);
jp.add(jp04);
jp.add(jp4);
getContentPane().add(jp);
jta=newJTextArea();
jta.setColumns(20);//設置文本域的大小
jta.setEditable(false);//設置文本域不可編輯
jta.setBackground(jp.getBackground());//設置文本域的背景色和面板一樣
getContentPane().add(jta);

jb.addActionListener(newActionListener(){//給按鈕添加事件

publicvoidactionPerformed(ActionEvente){//點擊按鈕,顯示信息到文本域
Stringname=jtf1.getText();
Stringnumber=jtf2.getText();
Stringclazz=jtf3.getText();
jta.setText("Younameis"+name+"numberis"+number+"classis"+clazz);
}
});
}

publicstaticvoidmain(String[]args){
newFrameDemo().setVisible(true);//創建窗口,被設置為可見
}
}


五: 拓展

雖然圖形界面的實現方法是多樣的, 我們一定要根據具體情況, 選擇一個比較優化的 合理的, 符合業務邏輯的實現方法

Ⅲ java界面設計

1、用戶名重復驗證,在輸入用戶名的input寫一個onchange事件,每次觸發這個事件用ajax非同步請專求後台查詢是屬否重復,在回調函數裡面提示給用戶輸入的用戶名是否重復。
2、兩次輸入密碼不一致驗證,這個不需要走後台,在確認密碼的input添加onchang事件,觸發之後取兩次輸入密碼的值在js裡面直接比較然後進行提示。

Ⅳ JAVA圖形界面設計

importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Graphics;

importjavax.swing.JFrame;
importjavax.swing.JPanel;

{

publicTestFrame(){

add(newCirclePanel());
setSize(300,230);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
} publicstaticvoidmain(String[]args){
newTestFrame().setVisible(true);
}

//繪制圖形的面板
classCirclePanelextendsJPanel{
intR=50;//直徑
@Override
protectedvoidpaintComponent(Graphicsg){
super.paintComponent(g);

g.setColor(Color.BLUE);//設置顏色為藍色
g.drawOval(80,30,R,R);//圓形外接矩形的左頂點坐標是80,30;
g.setColor(Color.BLACK);
g.drawOval(120,30,R,R);
g.setColor(Color.RED);
g.drawOval(160,30,R,R);
g.setColor(Color.YELLOW);
g.drawOval(100,65,R,R);
g.setColor(Color.GREEN);
g.drawOval(140,65,R,R);

g.setColor(Color.BLUE);//設置顏色為藍色
g.setFont(newFont("宋體",Font.BOLD,22));//設置字體
g.drawString("奧運五環旗",90,160);
}
}
}

Ⅳ eclipse怎麼進行 可視化java界面設計

安裝windowbuilder插件即可
首先,需要知道自己的Eclipse是什麼版本的.可以到Eclipse的安裝目錄下用記事本打開.eclipseproct文件,version後面對應的就是版本號.
打開http://eclipse.org/windowbuilder/download.php,裡面有Update Sites,下面有Eclipse Version,Release Version,Integration Version欄目.選擇對應版本的link.復制URL地址.
打開Eclipse,選擇Help→Install New Software,在work with裡面把得到的URL復制進去.勾選所有,點擊Next安裝就好了.是已經安裝過的,所以按鈕是灰色的。
然後新建項目,New→Project→WindowBuilder→SWT Designer→SWT/JFace Java Project
然後建立一個包,在建類的時候選擇New→Other,選擇WindowBuilder→Swing Designer→Application Window.類建好之後點擊Design就可以進行可視化編輯了。

Ⅵ java界面設計

我覺得,頁面布來局什麼的源,這個不用說了吧。。就是邏輯而已,點擊「第一步」,判斷有沒有輸入,如果有輸入,判斷是不是正整數,如果條件符合,那麼第一格顯示輸入的值,然後第二格,處理下(其實就是for循環String,倒序)然後第三格=第一格+第二格的值;
第二步,同樣獲得第一步最後一個的和值,然後類似第一步。如下類似

Ⅶ java圖形界面設計

/**因為是用long型來存儲結果,所以如果你想求更大的階乘的話換類型或者用其它的求高精度數值類**/
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TestFact extends JFrame {
private JTextField jtfNum;
private JTextField jtfResult;
public TestFact() {

JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);

JLabel jlaInput = new JLabel("輸入一個數:");
jlaInput.setBounds(12, 94, 70, 28);
panel.add(jlaInput);

jtfNum = new JTextField();
jtfNum.setBounds(121, 94, 114, 30);
panel.add(jtfNum);
jtfNum.setColumns(10);

JButton jbtCompute = new JButton("求階乘");
jbtCompute.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fact();
}

});
jbtCompute.setBounds(67, 151, 117, 24);
panel.add(jbtCompute);

jtfResult = new JTextField();
jtfResult.setEnabled(false);
jtfResult.setBounds(12, 34, 326, 28);
panel.add(jtfResult);
jtfResult.setColumns(10);

this.setTitle("求階乘");
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setSize(362,300);
this.setVisible(true);
}
private void fact() {
String s = jtfNum.getText().trim();
int num;
long fact = 1;
if(s==null||s.equals("")){

JOptionPane.showMessageDialog(null, "您還沒有輸入呢!");
return ;
}
try{
num = Integer.parseInt(s);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "您的輸入數字有誤哦!");
return ;
}
if(num<0){
JOptionPane.showMessageDialog(null, "您的輸入數字為負數!");
return ;
}

for(int i = 1; i<= num; i++){
fact *=i;
}

jtfResult.setText(fact+"");
}

public static void main(String[] args) {
new TestFact();
}
}

Ⅷ java圖形用戶界面設計

import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;

class SumTest {
private int x;
private int y;

public SumTest() {
setXY();
}

private void setXY() {
this.x = (int) (Math.random() * 100);
this.y = (int) (Math.random() * 100);
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String display() {
return "X :" + getX() + " Y :" + getY();
}

}

public class Panel extends JFrame {

private static final long serialVersionUID = 1L;
private JLabel labelDisplay;
private JLabel labelSum;
private JLabel labelError;
private JTextField textFieldSum;
private JButton submitButton;
private JButton cancelButton;
private SumTest st;
private int x;
private int y;

private Panel(){
super("Add Check");
st = new SumTest();
x = st.getX();
y = st.getY();
}

private void PanelMethod(){

setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new FlowLayout());

labelSum = new JLabel("SumResult:");
labelDisplay = new JLabel();
labelDisplay.setText(st.display() + " ");
textFieldSum = new JTextField(5);

submitButton = new JButton("Sumbit");
cancelButton = new JButton("Clear");

labelError = new JLabel();

class cleanB implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
textFieldSum.setText("");
}
}

class submitB implements ActionListener {

public void actionPerformed(ActionEvent arg0){
String sum = "";
int sumResult = 0;
sum = textFieldSum.getText();
try {
sumResult = Integer.parseInt(sum);
} catch (NumberFormatException e) {
e.printStackTrace();
}
if(x+y == sumResult) {
labelError.setText("Right");
} else {
labelError.setText("Wrong!Input Again");
}
}
}

cancelButton.addActionListener(new cleanB());
submitButton.addActionListener(new submitB());

getContentPane().add(labelDisplay);
getContentPane().add(labelSum);
getContentPane().add(textFieldSum);
getContentPane().add(submitButton);
getContentPane().add(cancelButton);
getContentPane().add(labelError);

setSize(180, 160);
}

public static void main(String[] args){
final Panel frame = new Panel();
frame.PanelMethod();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocation(400, 400);
frame.setResizable(false);
frame.setVisible(true);
}
}

測試通過,有問題可以發消息給我

Ⅸ JAVA 界面設計怎麼插入背景圖片

JPanel jp=new JPanel()://定義面板並初始化

Icon iocn=new ImageIcon("C:/My Documents/tupian.jpg");//定義圖片並初始化,寫上圖片的絕對路徑

JLabel jl=new JLabel(icon)://把圖片放在標簽上

jp.add(jl);//往面板上添加標簽注意:面板JPanel不能之間添加圖片iocn,icon需要放在標簽JLabel上,才能在JPanel上顯示

Ⅹ Java程序界面設計

界面方面主要是前端的框架,這樣就可以更好的參與這個體系的課程學習哦!

熱點內容
美發店認證 發布:2021-03-16 21:43:38 瀏覽:443
物業糾紛原因 發布:2021-03-16 21:42:46 瀏覽:474
全國著名不孕不育醫院 發布:2021-03-16 21:42:24 瀏覽:679
知名明星確診 發布:2021-03-16 21:42:04 瀏覽:14
ipad大專有用嗎 發布:2021-03-16 21:40:58 瀏覽:670
公務員協議班值得嗎 發布:2021-03-16 21:40:00 瀏覽:21
知名書店品牌 發布:2021-03-16 21:39:09 瀏覽:949
q雷授權碼在哪裡買 發布:2021-03-16 21:38:44 瀏覽:852
圖書天貓轉讓 發布:2021-03-16 21:38:26 瀏覽:707
寶寶水杯品牌 發布:2021-03-16 21:35:56 瀏覽:837