设置长度:
textfield.setColumns(长度);
textfield.setColumns(长度);
解决方案 »
- javasript如何设置这样的焦点??
- 对于这一小问~~我百思不得其解~~~郁闷了~~谁能指点迷津~~
- java如何创建一个只能输入数字的文本框啊?
- 请大家帮忙!!!
- 对arrayList中的数据进行排名(不是排序)??
- 晕哟,我写的ftp上传的applet怎么运行不了哟?
- 使用sybase出现SET CHAINED command not allowed within multi-statement transaction. 为什么会出现这种情况呢
- Java applet 如何嵌入ppt 啊
- java中怎样做本地化?
- 遇到一个问题,字符串引用打印的问题
- 如何在applet中产生一个对话框?
- ----正则表达式的问题-----
textfield.setBounds(new Rectangle(30, 30, 30, 30));
前两个参数是TextField在FRAME中的位置,后两个参数就是长宽大小了
textfield.setBounds(new Rectangle(30, 30, 30, 30));
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class lending extends JFrame implements ActionListener {
JLabel lbltitle,lblname,lblpassword,l1,l2,l3,l4;
JTextField txtname;
JPanel p1,p2,p3;
JPasswordField txtpassword;
JButton cmdenter,cmdexit;
lending(){
// System.out.println("lili");
lbltitle=new JLabel("欢迎使用本系统 ");
lblname=new JLabel("姓名:",SwingConstants.RIGHT);
lblpassword=new JLabel("密码:",SwingConstants.RIGHT);
txtname=new JTextField(30);
txtname.setSize(20,50);
txtname.setBounds(new Rectangle(10,50,30,30));
txtpassword=new JPasswordField(30);
txtpassword.setEchoChar('#');
l1=new JLabel();
l2=new JLabel();
l3=new JLabel();
l4=new JLabel();
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
cmdenter=new JButton(" 确 定 ");
cmdexit=new JButton(" 退 出 ");
this.getContentPane().setForeground(Color.blue);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(p1,BorderLayout.NORTH);
this.getContentPane().add(p2,BorderLayout.CENTER);
getContentPane().add(p3,BorderLayout.SOUTH);
// getContentPane().add(new JScrollPane(txts));
Font f1=new Font("fmi",Font.BOLD+Font.ITALIC,20);
p1.add(lbltitle);
lbltitle.setFont(f1);
lbltitle.setForeground(new Color(127,122,235));
Font f=new Font("ff",Font.PLAIN,15);
p2.setLayout(new GridLayout(3,3,10,20));
lblname.setForeground(Color.blue);
lblname.setFont(f);
p2.add(lblname);
p2.add(txtname);
p2.add(l1);
cmdenter.addActionListener(this);
cmdexit.addActionListener(this);
lblpassword.setForeground(Color.blue);
lblpassword.setFont(f);
p2.add(lblpassword);
p2.add(txtpassword);
p2.add(l2);
p2.add(l3);
p2.add(l4);
cmdenter.setForeground(Color.blue);
cmdenter.setFont(f);
p3.add(cmdenter);
cmdexit.setForeground(Color.blue);
cmdexit.setFont(f);
p3.add(cmdexit);
this.setSize(300,200);
this.setTitle("地址簿登陆");
this.show(true);
}
public static void main(String args[]){
lending l=new lending();
} public void actionPerformed(ActionEvent e) {
// TODO: Add your code here
Object obj=e.getSource();
if (obj==cmdenter){
txtname.setText("你好");
txtpassword.setText("000");
}
else{
txtname.setText("error");
txtpassword.setText("99999");
}
}
}