Ⅰ 用java語言設計一個界面,
首先:採用什麼技術實現
java語言可以使用awt 和swing等技術實現圖形界面
推薦使用Swing,因為Swing比AWT更專業,更漂亮,組件更豐富,功能更強大。
2. 其次:分析採用什麼布局
邊界布局BorderLayout,配合表格布局GridLayout,既簡單又美觀
3. 最後:分析需求中需要用的組件
學生姓名 學號 顯示信息 需要用到文本框JTextField
單選按鈕 需要用到組件JRadioButton
復選框 需要用到組件JCheckBox
組合框 需要用到組件JComboBox
圖片效果
//導入所需要的包
importjava.awt.event.*;
importjavax.swing.border.*;
importjavax.swing.*;
importjava.awt.*;
{//寫一個類繼承自JFrame窗體
	//定義組件
	=1L;
	privateJPanelcontentPane;
	privateJTextFieldtfName,tfNum,allInfo;
	privateJRadioButtonrb1,rb2;
	privateJCheckBoxcb1,cb2,cb3;
	privateJComboBox<String>t1,t2,t3;
	publicstaticvoidmain(String[]args){
		EventQueue.invokeLater(newRunnable(){
			publicvoidrun(){
				try{
					ClassFrameframe=newClassFrame();//創建一個窗口實例
					frame.setVisible(true);//讓該窗口實例可見
				}catch(Exceptione){
					e.printStackTrace();
				}
			}
		});
	}
	/**
	*窗口屬性的設置,內部組件的初始化
	*/
	publicClassFrame(){
		setTitle("選課ing...");//標題
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設置關閉是退出JVM
		setSize(450,339);//設置窗體大小
		setLocationRelativeTo(null);//窗體居中
		contentPane=newJPanel();//內容面板
		contentPane.setBorder(newEmptyBorder(5,5,5,5));
		contentPane.setLayout(newBorderLayout(0,0));//設置布局
		setContentPane(contentPane);
		JPanelpanel=newJPanel(newGridLayout(5,1,5,10));//5行1列的表格布局
		panel.setBorder(newTitledBorder(null,"",TitledBorder.LEADING,TitledBorder.TOP,null,null));
		contentPane.add(panel,BorderLayout.CENTER);//給panel添加邊框
		JPanelpanel_1=newJPanel();
		panel.add(panel_1);
		JLabellabel=newJLabel("姓名");
		panel_1.add(label);
		tfName=newJTextField();
		panel_1.add(tfName);
		tfName.setColumns(10);
		JLabellabel_2=newJLabel("學號");
		panel_1.add(label_2);
		tfNum=newJTextField();
		tfNum.setColumns(10);
		panel_1.add(tfNum);
		rb1=newJRadioButton("男");
		panel_1.add(rb1);
		rb1.setSelected(true);//設置單選按鈕中,默認選擇的按鈕
		rb2=newJRadioButton("女");
		panel_1.add(rb2);
		ButtonGroupbts=newButtonGroup();//單選按鈕需要加入同一個ButonGroup中才能生效
		bts.add(rb1);
		bts.add(rb2);
		JPanelpanel_2=newJPanel();
		panel.add(panel_2);
		cb1=newJCheckBox("高等數學");
		panel_2.add(cb1);
		t1=newJComboBox<String>();
		t1.setModel(newDefaultComboBoxModel<String>(newString[]{"林老師","趙老師","孫老師"}));
		panel_2.add(t1);
		JPanelpanel_3=newJPanel();
		panel.add(panel_3);
		cb2=newJCheckBox("世界經濟");
		panel_3.add(cb2);
		t2=newJComboBox<String>();
		t2.setModel(newDefaultComboBoxModel<String>(newString[]{"張老師","劉老師"}));
		panel_3.add(t2);
		JPanelpanel_4=newJPanel();
		panel.add(panel_4);
		cb3=newJCheckBox("音樂賞析");
		panel_4.add(cb3);
		t3=newJComboBox<String>();
		t3.setModel(newDefaultComboBoxModel<String>(newString[]{"王老師","周老師"}));
		panel_4.add(t3);
		JPanelpanel_5=newJPanel();
		panel.add(panel_5);
		JButtonjbOk=newJButton("確定");
		panel_5.add(jbOk);
		JButtonjbRest=newJButton("重填");
		panel_5.add(jbRest);
		JPanelpanelSouth=newJPanel();
		contentPane.add(panelSouth,BorderLayout.SOUTH);
		JLabellabe=newJLabel("選課信息");
		labe.setHorizontalAlignment(SwingConstants.LEFT);
		panelSouth.add(labe);
		allInfo=newJTextField();
		allInfo.setColumns(30);
		panelSouth.add(allInfo);
		JPanelpanelNorth=newJPanel();
		contentPane.add(panelNorth,BorderLayout.NORTH);
		JLabellabelTitle=newJLabel("學生選課界面");
		labelTitle.setForeground(Color.DARK_GRAY);
		labelTitle.setFont(newFont("宋體",Font.BOLD,20));
		panelNorth.add(labelTitle);
		//給確定按鈕添加事件處理代碼
		jbOk.addActionListener(newActionListener(){
			publicvoidactionPerformed(ActionEvente){
				StringBuilderinfo=newStringBuilder();
				Stringname=tfName.getText();
				Stringnum=tfNum.getText();
				Stringsex;
				if(rb1.isSelected()){
					sex="男";
				}else{
					sex="女";
				}
				info.append(name+num+sex);
				if(cb1.isSelected()){
					Stringc=cb1.getText();
					Stringt=t1.getSelectedItem().toString();
					info.append(""+c+t);
				}
				if(cb2.isSelected()){
					Stringc=cb2.getText();
					Stringt=t2.getSelectedItem().toString();
					info.append(""+c+t);
				}
				if(cb3.isSelected()){
					Stringc=cb3.getText();
					Stringt=t3.getSelectedItem().toString();
					info.append(""+c+t);
				}
				allInfo.setText(info.toString());//把學生信息和選課信息放到文本框
			}
		});
		//給重填按鈕設置事件處理代碼
		jbRest.addActionListener(newActionListener(){
			publicvoidactionPerformed(ActionEvente){
				tfName.setText("");
				tfNum.setText("");
				rb1.setSelected(true);
				cb1.setSelected(false);
				t1.setSelectedIndex(0);
				cb2.setSelected(false);
				t2.setSelectedIndex(0);
				cb3.setSelected(false);
				t3.setSelectedIndex(0);
				allInfo.setText("");
			}
		});
	}
}
Ⅱ 用java寫一個登陸界面代碼。
具體框架使用jframe,文本框組件:JTextField;密碼框組件:JPasswordField;標簽組件:JLabel;復選框組件:JCheckBox;單選框組件:JRadioButton;按鈕組件JButton。
登錄界面:

Swing 是一個為Java設計的GUI工具包。
Swing是JAVA基礎類的一部分。
Swing包括了圖形用戶界面(GUI)器件如:文本框,按鈕,分隔窗格和表。
Swing提供許多比AWT更好的屏幕顯示元素。它們用純Java寫成,所以同Java本身一樣可以跨平台運行,這一點不像AWT。它們是JFC的一部分。它們支持可更換的面板和主題(各種操作系統默認的特有主題),然而不是真的使用原生平台提供的設備,而是僅僅在表面上模仿它們。這意味著你可以在任意平台上使用JAVA支持的任意麵板。輕量級組件的缺點則是執行速度較慢,優點就是可以在所有平台上採用統一的行為。
概念解析:
JFrame– java的GUI程序的基本思路是以JFrame為基礎,它是屏幕上window的對象,能夠最大化、最小化、關閉。
JPanel– Java圖形用戶界面(GUI)工具包swing中的面板容器類,包含在javax.swing 包中,可以進行嵌套,功能是對窗體中具有相同邏輯功能的組件進行組合,是一種輕量級容器,可以加入到JFrame窗體中。。
JLabel– JLabel 對象可以顯示文本、圖像或同時顯示二者。可以通過設置垂直和水平對齊方式,指定標簽顯示區中標簽內容在何處對齊。默認情況下,標簽在其顯示區內垂直居中對齊。默認情況下,只顯示文本的標簽是開始邊對齊;而只顯示圖像的標簽則水平居中對齊。
JTextField–一個輕量級組件,它允許編輯單行文本。
JPasswordField– 允許我們輸入了一行字像輸入框,但隱藏星號(*) 或點創建密碼(密碼)
JButton– JButton 類的實例。用於創建按鈕類似實例中的 "Login"。
Ⅲ 用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);
}
}
Ⅳ 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做好的登陸界面,當登陸成功後跳轉到下個頁面的代碼是什麼
用java做好的登陸界面,當登陸成功後跳轉到下個頁面的代碼如下:
如果登陸驗專證是在jsp中,那麼跳轉可以寫成屬
1.response.sendRedirct("跳轉到頁面");
2.<jsp:forward page="跳轉頁面"/>
3.response.setHeader("Location","");
如果是登陸驗證是在servlet中,那麼中轉可以寫成
1.response.sendRedirect("/a.jsp");
2.RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
也可以使用js代碼實現:
<script>
    function validate(){
window.location.href="/index.jsp";
}
</script>
Ⅵ java怎麼做swing界面
swing做界面,一般需要一種基本知識:
一:關於布局的知識,常用的布局要熟悉,比如邊界布局,流式布局,絕對布局,網格布局等. 布局決定了組件(按鈕,文本框,下拉框等)所在的位置
二:關於事件響應機制,比如點擊按鈕事件,如何響應.
三:一些常用的組件,按鈕, 文本框, 下拉框,復選按鈕, 單選按鈕, 等
舉例: 簡單的代碼,實現給窗口隨機更換背景色
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
{
publicDemoFrame(){
JButtonjb1=newJButton("點擊換背景色");//定義按鈕組件
jb1.addActionListener(this);//給按鈕添加事件響應機制,按鈕點擊時執行actionPerformed方法
add(jb1);//把組件添加到窗口
setLayout(newFlowLayout());//流式布局
setTitle("Color");//窗口標題
setSize(300,200);//大小
setLocationRelativeTo(null);//居中
setDefaultCloseOperation(EXIT_ON_CLOSE);//點擊關閉時退出系統
setVisible(true);//窗口可見
}
publicstaticvoidmain(String[]args){//main方法,啟動窗口
newDemoFrame();//創建窗口
}
publicvoidactionPerformed(ActionEvente){//當按鈕被點擊時,執行下面的代碼
//隨機顏色,並設置成為窗口的背景色
getContentPane().setBackground(newColor((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256)));
}
}
