请JAVA大神帮忙写一个窗口界面的程序,可以读写文件的,有一定的功能的就行,谢谢啦
展开全部
ackage com.tx.gui;
import java.awt.Button;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class FirstFJFrameDemo {
public static void main(String[] args) {
JFrame jf = new JFrame("第一个窗口");
jf.setBounds(100, 100, 400, 300);
jf.setLayout(null);
// jf.setBackground();
jf.setVisible(true);
JLabel jl = new JLabel("输入qq号码:不超过12位,只允许输入整数");
jl.setBounds(50, 20, 300,50);
jf.add(jl);
TextField tf = new TextField();
tf.setBounds(50, 70, 250,20);
jf.add(tf);
TextArea ta = new TextArea();
ta.setBounds(50, 100 ,250, 80);
jf.add(ta);
Button b =new Button();
b.setLabel("点击");
b.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
ta.append(tf.getText());
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
});
b.setBounds(320, 70, 40,20);
jf.add(b);
tf.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
if(e.getKeyChar()>KeyEvent.VK_9||e.getKeyChar()<KeyEvent.VK_0) {
e.consume();
JOptionPane.showMessageDialog(jf, "输入的不是数字","温馨提示",JOptionPane.WARNING_MESSAGE);
}
if(tf.getText().length()>11) {
e.consume();
}
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
}
});
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.Button;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class FirstFJFrameDemo {
public static void main(String[] args) {
JFrame jf = new JFrame("第一个窗口");
jf.setBounds(100, 100, 400, 300);
jf.setLayout(null);
// jf.setBackground();
jf.setVisible(true);
JLabel jl = new JLabel("输入qq号码:不超过12位,只允许输入整数");
jl.setBounds(50, 20, 300,50);
jf.add(jl);
TextField tf = new TextField();
tf.setBounds(50, 70, 250,20);
jf.add(tf);
TextArea ta = new TextArea();
ta.setBounds(50, 100 ,250, 80);
jf.add(ta);
Button b =new Button();
b.setLabel("点击");
b.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
ta.append(tf.getText());
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
});
b.setBounds(320, 70, 40,20);
jf.add(b);
tf.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
if(e.getKeyChar()>KeyEvent.VK_9||e.getKeyChar()<KeyEvent.VK_0) {
e.consume();
JOptionPane.showMessageDialog(jf, "输入的不是数字","温馨提示",JOptionPane.WARNING_MESSAGE);
}
if(tf.getText().length()>11) {
e.consume();
}
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
}
});
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询