当前位置: 技术问答>java相关
应当怎样使用appletviewer?
来源: 互联网 发布时间:2015-04-22
本文导语: 刚开始学习swing,运行书上的例程,编译之后应当怎样才能使用appletwiewer? 源程序: TActionEvent.java /* * * */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TActionEvent extends JApplet { Container...
刚开始学习swing,运行书上的例程,编译之后应当怎样才能使用appletwiewer?
源程序:
TActionEvent.java
/*
*
*
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TActionEvent extends JApplet {
Container container;
JLabel label;
Icon speaker;
public void init() {
// 1. Get the handle on the applet's content pane.
container = this.getContentPane();
// 2. Create a speaker icon, add it to a Swing
// label, and add the label to the applet.
speaker = new ImageIcon("speaker.gif");
label = new JLabel(speaker);
//label.repaint();
container.add(label);
// 3. Create a source (button) for the action event.
JButton source = new JButton("Ring the bell!");
container.add(source, BorderLayout.SOUTH);
// 4. Register the action listener with the source.
source.addActionListener(new ButtonListener());
}
// 5. Define the listener class.
class ButtonListener implements ActionListener {
// 6. Interface method that has been implemented.
public void actionPerformed(ActionEvent ae) {
// Ring the bell...
int i=0;
while (i
源程序:
TActionEvent.java
/*
*
*
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TActionEvent extends JApplet {
Container container;
JLabel label;
Icon speaker;
public void init() {
// 1. Get the handle on the applet's content pane.
container = this.getContentPane();
// 2. Create a speaker icon, add it to a Swing
// label, and add the label to the applet.
speaker = new ImageIcon("speaker.gif");
label = new JLabel(speaker);
//label.repaint();
container.add(label);
// 3. Create a source (button) for the action event.
JButton source = new JButton("Ring the bell!");
container.add(source, BorderLayout.SOUTH);
// 4. Register the action listener with the source.
source.addActionListener(new ButtonListener());
}
// 5. Define the listener class.
class ButtonListener implements ActionListener {
// 6. Interface method that has been implemented.
public void actionPerformed(ActionEvent ae) {
// Ring the bell...
int i=0;
while (i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!