国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

用AWT組件實(shí)現(xiàn)登錄對(duì)話(huà)框

2019-11-18 15:21:09
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  作者:javazealot

/*本程序是模擬的中文Java技術(shù)網(wǎng)的登錄窗口,用AWT組件實(shí)現(xiàn)的,不過(guò)還有一些需要完善的地方,所以我希望能得到各位Java愛(ài)好者的建議*/

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

//對(duì)話(huà)框創(chuàng)建

class okcanceldialog extends Dialog implements ActionListener
{
Panel p;
Label top,name,passWord;
TextField inputname,inputpassword;
Button ok,cancel;
String data;
okcanceldialog(Frame hostFrame,String title,boolean dModal)
{
super(hostFrame,title,dModal);
p=new Panel();
p.setLayout(new FlowLayout());
setSize(300,200);
setLayout(new GridBagLayout());//用網(wǎng)格包裝布局為放置組件
GridBagConstraints gbb=new GridBagConstraints();
top=new Label("登 錄 窗 口 ");
gbb.gridx=1;
gbb.gridy=0;//在第一行顯示top標(biāo)簽
add(top,gbb);

name=new Label("會(huì)員名:");
gbb.gridx=GridBagConstraints.RELATIVE;
gbb.gridy=1;//在第二行顯示會(huì)員名標(biāo)簽和相應(yīng)文本框
add(name,gbb);
inputname=new TextField(20);
add(inputname,gbb);

password=new Label("密碼:");
gbb.gridx=GridBagConstraints.RELATIVE;
gbb.gridy=2;在第二行顯示密碼標(biāo)簽和相應(yīng)文本框
add(password,gbb);
inputpassword=new TextField(20);

add(inputpassword,gbb);
inputpassword.setEchoChar(´*´);

ok=new Button("確定");
p.add(ok);
ok.addActionListener(this);

cancel=new Button("放棄");
p.add(cancel);
cancel.addActionListener(this);
p.add(new Label(" "));//將兩個(gè)按鈕和一個(gè)含有很多空格的標(biāo)簽加入板(注:標(biāo)簽的 //作用是為了把按鈕擠在中間)
gbb.gridx=1;
gbb.gridy=3;//在第四行顯示板

add(p,gbb);
data=new String();

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}});//用以關(guān)閉窗 //口

}

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==ok){
data=" 您好,"+inputname.getText()+",歡迎光臨中文Java技術(shù)網(wǎng)!";
}else if(event.getSource()==cancel){
data=" 你沒(méi)有輸入! ";
}
setVisible(false);
}
}

//窗口創(chuàng)建
class dialogframe extends Frame implements ActionListener
{
Label firstpage,word;
Button enter;
okcanceldialog dialog;
dialogframe(String title)
{
super(title);
setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();

firstpage=new Label("Welcome to cn-java net");

enter=new Button("會(huì)員登錄");
gbc.gridy=0;
add(firstpage,gbc);

word=new Label(" 您還沒(méi)有登錄 ");
gbc.gridx=GridBagConstraints.RELATIVE;
gbc.gridy=1;
add(enter,gbc);

enter.addActionListener(this);
gbc.gridx=GridBagConstraints.RELATIVE;
gbc.gridy=2;//在第三行顯示歡迎詞
add(word,gbc);
dialog=new okcanceldialog(this,"登錄",true);

}

public void actionPerformed(ActionEvent event)
{
if(event.getSource()==enter){
dialog.setVisible(true);
word.setText(dialog.data);
}
} //此方法用來(lái)顯示對(duì)話(huà)框
}

//主類(lèi)
public abstract class mainclass implements ActionListener
{
public static void main(String[] args)
{
dialogframe f=new dialogframe("Welcome");//創(chuàng)建窗口實(shí)例
f.setSize(300,200);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}});
f.show();
}
}

附:本程序已通過(guò)調(diào)試,沒(méi)有任何錯(cuò)誤.

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 柘荣县| 安徽省| 大庆市| 安达市| 阿图什市| 武威市| 东阳市| 个旧市| 友谊县| 类乌齐县| 怀安县| 渑池县| 徐闻县| 肃北| 海伦市| 彩票| 扎兰屯市| 鹰潭市| 潮州市| 尚义县| 晋宁县| 叙永县| 东光县| 苍山县| 邢台市| 资阳市| 龙海市| 马尔康县| 忻州市| 类乌齐县| 文山县| 宜君县| 安乡县| 云安县| 新邵县| 正蓝旗| 昂仁县| 缙云县| 白水县| 景宁| 光泽县|