Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » 技术文章库  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 helloworld
jcghq



发贴: 0
积分: 0
于 2003-01-07 12:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class HelloWorld extends Applet implements ActionListener
{
private Button myButton1=null;
private Button myButton2=null;
private Button myButton3=null;
private Label lHello=null;
private Label lAnswer=null;

public void actionPerformed(ActionEvent e)
{
if((e.getSource()==newButton1()))
{
showHello(e);
}
if((e.getSource()==newButton2()))
{
showWhoAreU(e);
}
if((e.getSource()==newButton3()))
{
showReset(e);
}
}

private void showHello(ActionEvent arg)
{
try
{
newlHello().setText("Hello,World!");
}
catch(Throwable myExc)
{
handleException(myExc);
}
}
private void showWhoAreU(ActionEvent arg)
{
try
{
newlAnswer().setText("I am Java! and Who are you?");
}
catch(Throwable myExc)
{
handleException(myExc);
}
}

private void showReset(ActionEvent arg)
{
try
{
newlAnswer().setText("");
newlHello().setText("");
}
catch(Throwable myExc)
{
handleException(myExc);
}
}

private Button newButton1()
{
if(myButton1==null)
{
try
{
myButton1=new Button();
myButton1.setName("Button1");
myButton1.setFont(new Font("dialog",3,16));
myButton1.setBounds(59,228,111,31);
myButton1.setLabel("Hello");
}
catch(Throwable myExc)
{
handleException(myExc);
}
};
return myButton1;
}

private Button newButton2()
{
if(myButton2==null)
{
try
{
myButton2=new Button();
myButton2.setName("Button2");
myButton2.setFont(new Font("dialog",3,16));
myButton2.setBounds(229,227,120,32);
myButton2.setLabel("Who are you?");
}
catch(java.lang.Throwable myExc)
{
handleException(myExc);
}
};
return myButton2;
}

private Button newButton3()
{
if(myButton3==null)
{
try
{
myButton3=new Button();
myButton3.setName("Button3");
myButton3.setFont(new Font("helvetica",3,16));
myButton3.setBounds(408,228,90,30);
myButton3.setLabel("Reset");
}
catch(java.lang.Throwable myExc)
{
handleException(myExc);
}
};
return myButton3;
}

private Label newlHello()
{
if(lHello==null)
{
try
{
lHello=new Label();
lHello.setName("hello");
lHello.setText("");
lHello.setForeground(Color.blue);
lHello.setFont(new Font("helvetica",3,24));
lHello.setAlignment(Label.LEFT);
lHello.setBounds(108,40,200,30);
lHello.setEnabled(true);
}
catch(Throwable myExc)
{
handleException(myExc);
}
};
return lHello;
}

private Label newlAnswer()
{
if(lAnswer==null)
{
try
{
lAnswer=new Label();
lAnswer.setName("");
lAnswer.setFont(new Font("helvetica",3,32));
lAnswer.setAlignment(Label.LEFT);
lAnswer.setText("");
lAnswer.setBounds(108,118,550,76);
lAnswer.setForeground(Color.blue);
}
catch(Throwable myExc)
{
handleException(myExc);
}
};
return lAnswer;
}

private void handleException(Throwable excption)
{
}

private void initListener()
{
newButton1().addActionListener(this);
newButton2().addActionListener(this);
newButton3().addActionListener(this);
}

public void init()
{
try
{
setName("HelloWorld");
setLayout(null);
setSize(560,265);
add(newButton1(),newButton1().getName());
add(newButton2(),newButton2().getName());
add(newlHello(),newlHello().getName());
add(newlAnswer(),newlAnswer().getName());
add(newButton3(),newButton3().getName());
initListener();
}
catch(Throwable myExc)
{
handleException(myExc);
}
}
}

<HTML>
<HEAD>
<TITLE>
Hello World Applet
</TITLE>
</HEAD>
<BODY>
<H2>This is a Java Applet Example.</H2>
<H3>Press button "Hello" and the Applet reply to you</H3>
<H3>Press button "Who are you?" the Applet tell you who it is</H3>
<H3>and press button "Reset" will clear all these messgae on the window.</H3>
<APPLET code=HelloWorld.class width=650 height=350>
</APPLET>
<HR>
<A href="HelloWorld.java">View the source.</A>
</BODY>
</HTML>


dapan edited on 2003-01-08 16:25

作者 Re:helloworld [Re:jcghq]
mabinde



发贴: 0
积分: 0
于 2003-01-08 15:16 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
easy


作者 Re:helloworld [Re:jcghq]
palatum



CJSDN高级会员


发贴: 451
积分: 80
于 2003-01-08 16:23 user profilesend a private message to usersend email to palatumsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
贴这个东西的目的是什么?请说明一下。我好进行评估。



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923