⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientgui.java

📁 swing component example code illustrating JTabbedpane and JPanel.
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ClientGUI extends JFrame
{
	private JTextField nameField1,nameField2;
	private JPasswordField passwordField1,passwordField2;
	private JLabel stitle,title, name1, password1, name2, password2;
	private GridBagLayout layout;
    private GridBagConstraints constraints; 
    private JTabbedPane choice;
    private Container container;
    private JPanel titlePanel, empty;
	
	public ClientGUI()
	{
		super("Login");
		
		//get frame
		container = getContentPane();
		layout = new GridBagLayout();
      	container.setLayout(layout);  
      
     
		 // instantiate gridbag constraints
      	constraints = new GridBagConstraints();
		
		//page title
		titlePanel = new JPanel();
		titlePanel.setLayout(new GridLayout(2,1));
		titlePanel.setBackground(new Color(204,255,153));
		stitle = new JLabel("Hang Zhou No 4 High School", SwingConstants.CENTER);
		stitle.setFont (new Font ("Bickley Script", Font.BOLD + Font.ITALIC,40));
		//stitle.setForeground(new Color(60,30,20));
		title = new JLabel("Test Center", SwingConstants.CENTER);
		//title.setForeground(new Color(153,255,153));
		title.setFont( new Font("Serif", Font.PLAIN, 36));
		titlePanel.add(stitle);
		titlePanel.add(title);
		constraints.weightx = 10;
		constraints.weighty = 1;
		constraints.fill = GridBagConstraints.BOTH;
		addComponent (titlePanel, 0, 0, 3, 2);
		
		Icon icon1 = new ImageIcon("teacher.gif");
		Icon icon2 = new ImageIcon("student.gif");
		
		choice = new JTabbedPane();
		JPanel teacher = new JPanel();
		JPanel student = new JPanel();
		teacher.setBackground(new Color(153,153,0));
		student.setBackground(new Color(204,255,51));
	    //choice.setForeground(Color.blue);
		teacher.setLayout(new GridLayout(2,2,5,5));
		student.setLayout(new GridLayout(2,2,5,5));
	
		choice.addTab("Teacher", icon1, teacher,"Teacher Login");
		choice.addTab ("Student", icon2, student, "Student Login");
		constraints.weightx = 5;
		constraints.weighty = 1;
		constraints.fill = GridBagConstraints.BOTH;
		addComponent(choice,3,0,4,4);
		
		name1 = new JLabel ("Teacher ID", SwingConstants.CENTER);
		name1.setFont(new Font("Arail", Font.ITALIC,20));
		name1.setForeground(Color.black);		
		nameField1 = new JTextField ("Enter your ID here", SwingConstants.CENTER);
		teacher.add(name1);
		teacher.add(nameField1);
		name2 = new JLabel ("Student ID", SwingConstants.CENTER);
		name2.setFont(new Font("Arail", Font.ITALIC,20));
		name2.setForeground(Color.black);
		nameField2 = new JTextField ("Enter your ID here");
		student.add(name2);
		student.add(nameField2);
		
		password1 = new JLabel ("Password", SwingConstants.CENTER);
		password1.setFont(new Font("Arial", Font.ITALIC,20));
	    password1.setForeground(Color.black);
		passwordField1 = new JPasswordField ("");
		teacher.add(password1);
		teacher.add(passwordField1);
		password2 = new JLabel ("Password", SwingConstants.CENTER);
	    password2.setFont(new Font("Arial", Font.ITALIC,20));
	    password2.setForeground(Color.black);
		passwordField2 = new JPasswordField ("");
		student.add(password2);
		student.add(passwordField2);
		 
		 empty = new JPanel();
		 empty.setBackground(new Color(204,255,152));
		 constraints.weightx = 5;
		constraints.weighty = 1;
		constraints.fill = GridBagConstraints.BOTH;
		 addComponent(empty, 7,0,4,4);
		
		setSize(500, 500);
		setVisible(true);
		
	}
	
	private void addComponent( Component component,
      int row, int column, int width, int height )
   {
      // set gridx and gridy 
      constraints.gridx = column;
      constraints.gridy = row;

      // set gridwidth and gridheight
      constraints.gridwidth = width;   
      constraints.gridheight = height;

      // set constraints and add component
      layout.setConstraints( component, constraints );  
      container.add( component );      
   }
   
	public static void main(String args[])
	{
		ClientGUI login = new ClientGUI();
		login.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
	}
		
		
		
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -