📄 logpanel.java
字号:
import javax.swing.*;
import java.awt.*;
//import colorLabel;
public class logPanel extends JPanel
{
//public ...? i can't make sure of the next two panel
Panel plging;
Panel plged;
JTextField tfName;
JPasswordField pfPass;
Button bnok;
Button bnreg;
Label ldisp;
GridBagLayout gl;
GridBagConstraints gbc;
CardLayout cl;
public logPanel()
{
plging=new Panel();
plged=new Panel();
gl=new GridBagLayout();
gbc=new GridBagConstraints();
cl=new CardLayout();
this.setLayout(cl);
Label lName=new Label("UserName");
Label lPass=new Label("Password");
lName.setBackground(Color.blue);
lPass.setBackground(Color.blue);
tfName=new JTextField(5);
tfName.setText("");
pfPass=new JPasswordField(5);
pfPass.setText("pass");
bnok=new Button(" OK ");
bnreg=new Button("Register");
ldisp=new Label("Please Login:");
//add sub panel of the first card
plging.setLayout(new BorderLayout());
Panel plgingc=new Panel();
plgingc.setLayout(gl);
gbc.insets=new Insets(1,1,1,1);
gbc.anchor=GridBagConstraints.EAST;
plging.add("Center",plgingc);
plging.add("South",ldisp);
//plging.add(lName,gbc);
addComp(plgingc,lName,1,1,1,1);
addComp(plgingc,tfName,3,1,1,1);
addComp(plgingc,lPass,1,2,1,1);
addComp(plgingc,pfPass,3,2,1,1);
addComp(plgingc,bnok,1,3,1,1);
addComp(plgingc,bnreg,3,3,1,1);
this.add("loging",plging);
//add sub panel the two card
this.add("loged",plged);
//show the first card
cl.show(this,"loging");
}
public void addComp
(Panel p,Component cmp ,int gridx,int gridy,int w,int h)
{
gbc.gridx=gridx;
gbc.gridy=gridy;
gbc.gridwidth=w;
gbc.gridheight=h;
p.add(cmp,gbc);
}
public void changeCard(Icon icn)
{
plged.setLayout(new BorderLayout());
//the current layoutManager is flowlayout
//Label lws=new Label("Welcome You !!");
//Label lns=new Label(tfName.getText());
colorLabel lws=new colorLabel("Hi! "+tfName.getText()+",Welcome you :) ",15);
plged.add("North",lws);
JLabel licn=new JLabel(icn);
plged.add("Center",licn);
//plged.add(lns);
cl.show(this,"loged");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -