本文目錄一覽:
- 1、Java程序界面設計?
- 2、java界面設計
- 3、用java設計一個簡單的界面設計,越簡單越好,謝謝
- 4、Java 界面設計
- 5、JAVA的圖形界面的布局設計有哪些,各種布局的用法。
- 6、eclipse怎麼進行 可視化java界面設計?
Java程序界面設計?
可以使用jswing包,這個包主要用於開發純JAVA得界面,網上也有安裝與使用教程,容易上手。
還有一種可以使用JAVA web作界面,不過需要改動的地方較多,不易上手。
java界面設計
你已經將p1和p2添加到p中,所以只需要向Frame添加一個p就可以了
this.setContentPane(p1); //去掉
this.setContentPane(p2); //去掉
this.setContentPane(p); //將這句改成this.add(p);
修改後的程序我運行了,可以顯示了。你試試吧 不懂在追問
用java設計一個簡單的界面設計,越簡單越好,謝謝
用java設計一個簡單的界面可以參考如下實例:
import javax.swing.JFrame;//框架
import javax.swing.JPanel;//面板
import javax.swing.JButton;//按鈕
import javax.swing.JLabel;//標籤
import javax.swing.JTextField;//文本框
import java.awt.Font;//字體
import java.awt.Color;//顏色
import javax.swing.JPasswordField;//密碼框
import java.awt.event.ActionListener;//事件監聽
import java.awt.event.ActionEvent;//事件處理
import javax.swing.JOptionPane;//消息窗口public class UserLogIn extends JFrame{
public JPanel pnluser;
public JLabel lbluserLogIn;
public JLabel lbluserName;
public JLabel lbluserPWD;
public JTextField txtName;
public JPasswordField pwdPwd;
public JButton btnSub;
public JButton btnReset;
public UserLogIn(){
pnluser = new JPanel();
lbluserLogIn = new JLabel();
lbluserName = new JLabel();
lbluserPWD = new JLabel();
txtName = new JTextField();
pwdPwd = new JPasswordField();
btnSub = new JButton();
btnReset = new JButton();
userInit();
}
public void userInit(){
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(new Font(“宋體”,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(new ActionListener()//匿名類實現ActionListener接口
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(155,120,60,20);
this.btnReset.addActionListener(new ActionListener()//匿名類實現ActionListener接口
{
public void actionPerformed(ActionEvent e){
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);//設置框架可顯
}
public void btnsub_ActionEvent(ActionEvent e){
String name = txtName.getText();
String pwd = String.valueOf(pwdPwd.getPassword());
if(name.equals(“”)){
JOptionPane.showMessageDialog(null,”賬號不能為空”,”錯誤”,JOptionPane.ERROR_MESSAGE);
return;
}else if (pwd.equals(“”)){
JOptionPane.showMessageDialog(null,”密碼不能為空”,”錯誤”,JOptionPane.ERROR_MESSAGE);
return;
}else if(true){
this.dispose();
}else{
JOptionPane.showMessageDialog(null,”賬號或密碼錯誤”,”錯誤”,JOptionPane.ERROR_MESSAGE);
return;
}
}
public void btnreset_ActionEvent(ActionEvent e){
txtName.setText(“”);
pwdPwd.setText(“”);
}
public static void main(String[] args){
new UserLogIn();
}
}
Java 界面設計
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import java.awt.GridBagConstraints;
public class Test1 extends JPanel {
private static final long serialVersionUID = 1L;
private JSplitPane jSplitPane = null;
/**
* This is the default constructor
*/
public Test1() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridy = 0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridx = 0;
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
this.add(getJSplitPane(), gridBagConstraints);
}
/**
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
*/
private JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
}
return jSplitPane;
}
}
樓主是不是要這種的效果???
JAVA的圖形界面的布局設計有哪些,各種布局的用法。
基本有五種
BorderLayout 邊界布局管理器
將容器分為東、南、西、北、中五個區域
分別用BorderLayout.SOUTH BorderLayout.NORTH BorderLayout.EAST BorderLayout.WEST BorderLayout.CENTER
FlowLayout 流式布局管理器
按照組件的添加順序將組件從左到右放置在容器中。允許左對齊、居中對齊、或右對齊
GridLayout網格布局管理器
將容器分割成多行多列 按照組件添加的順序一次講組件從左到右放置
GridBagLayout網格包布局管理器
允許組件中各個組件的大小各不相同
CardLayout 卡片布局管理器
將界面看成一些列的卡片,每一個卡片都有一個容器,任何時候只有一張卡片時可見的
構造方法有CradLayout()和CradLayout(int hgap,int vgap)
參數hgap表示卡片和容器的左右邊界之間的間隙,參數vgap表示卡片和容器的上下邊界之間的間隙
eclipse怎麼進行 可視化java界面設計?
進行eclipse可視化java界面設計步驟如下:
一、先新建一個普通的java工程。
二、為這個java工程添加有可視化界面的java類,選擇新建中的other選項。
三、找到windows build里的jFrame,即主界面,進行新建有界面的java。
四、點擊Design進入可視化編輯界面、
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/236651.html