
import javaawt;
import javaawtevent;
import javaxswing;
public class DengLu extends JFrame implements ActionListener
{
//与0紫电清霜0不同的是,我继承的是JFrame
JLabel lb1;
JLabel lb2;
JLabel lb3;
JTextField in1;
JButton btn1,btn2;
JPasswordField in2;
int count=0;
public DengLu()
{
setSize(200,200);
Container con=getContentPane();
consetLayout(new FlowLayout());
lb1 = new JLabel("请输入用户名");
in1 =new JTextField(5);
lb2 = new JLabel("请输入密码");
in2 =new JPasswordField(5);
btn1=new JButton ("确定");
btn2=new JButton ("取消");
lb3 =new JLabel();
conadd(lb1);
conadd(in1);
conadd(lb2);
conadd(in2);
conadd(btn1);
conadd(btn2);
conadd(lb3);
btn1addActionListener(this);
btn2addActionListener(this);
setVisible(true);
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(egetSource()==btn1)
{
if(new String(in2getPassword())equals("123")) //0紫电清霜0写的getText()方法已经过时了。
{
lb3setText("密码输入正确");
}
else
{
lb3setText("密码输入错误!");
count++;
}
if(count==3)
Systemexit(0);
}
if(egetSource()==btn2)
Systemexit(0);
}
public static void main(String[] args)
{
DengLu dl = new DengLu();
}
}
package dos;
import javaawtGraphics;
import javaawtPrintJob;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJPanel;
import javaxswingJTextArea;
public class t6 {
public static void main(String args[]) {
MyFrame f = new MyFrame();
fsetBounds(70, 70, 570, 280);
fsetVisible(true);
fvalidate();
}
}
class MyFrame extends JFrame implements ActionListener {
PrintJob p = null;
Graphics g = null;
JTextArea text = new JTextArea(10, 10);
JButton printTextFied = new JButton("打印文本框"),
printFrame = new JButton("打印窗口"),
printButton = new JButton("打印按钮");
MyFrame() {
super("在应用程序中打开");
/printTextFiedadd(this);
printFrameaddActionListener(this);
printButtonaddActionListener(this);
add(text, "Center");/
JPanel panel = new JPanel();
paneladd(printTextFied);
paneladd(printFrame);
paneladd(printButton);
add(panel, "South");
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (egetSource() == printTextFied) {
p = getToolkit()getPrintJob(this, "OK", null);
g = pgetGraphics();
gtranslate(120, 200);
textpaint(g);
gdispose();
pend();
} else if (egetSource() == printFrame) {
p = getToolkit()getPrintJob(this, "OK", null);
g = pgetGraphics();
thisprintAll(g);
gdispose();
pend();
} else if (egetSource() == printButton) {
p = getToolkit()getPrintJob(this, "OK", null);
g = pgetGraphics();
gtranslate(120, 200);
printTextFiedpaintAll(g);
gtranslate(78, 0);
printFrameprintAll(g);
gtranslate(66, 0);
printButtonpaintAll(g);
gdispose();
pend();
}
}
/public static void main(String args[]) {
new t6();
}/
}
以上就是关于关于JAVA的GUI图形界面问题~~~求高人解答~全部的内容,包括:关于JAVA的GUI图形界面问题~~~求高人解答~、Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)