2007-12-12

一些代码 APPLET,窗口APPLICATION

关键字: APPLET

1.APPLET:

java 代码
  1. import java.awt.Graphics;   
  2. import java.applet.Applet;   
  3. public class TimeFlies extends Applet{   
  4. public void paint(Graphics g){   
  5.     g.drawString("1111111111111",15,20);   
  6. }   
  7. }   

2.APPLICATION窗口:

java 代码
  1. //欢迎你参加JAVA考试   
  2. import java.awt.*;   
  3. import  java.awt.event.*;   
  4. import javax.swing.*;   
  5.   
  6. public class WelcomeTest {   
  7.        
  8.         public static void main(String args[])   
  9.         {   
  10.             WelcomeFrame frame=new WelcomeFrame();   
  11.             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
  12.                
  13.             frame.show();   
  14.         }   
  15.     }   
  16.     class   WelcomeFrame extends JFrame   
  17.     {   
  18.         public WelcomeFrame()   
  19.         {   
  20.             setTitle("Welcome ");   
  21.             setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);   
  22.             WelcomePanel panel=new WelcomePanel();   
  23.             Container contentPane=getContentPane();   
  24.             contentPane.add(panel);   
  25.                
  26.         }   
  27.            
  28.         public static final int DEFAULT_WIDTH=300;   
  29.         public static final int DEFAULT_HEIGHT=200;   
  30. }   
  31.        
  32. class WelcomePanel extends JPanel   
  33. {   
  34.     public WelcomePanel()   
  35.     {   
  36.     JLabel prompt = new JLabel("请输入你的名字");   
  37.         final JTextField input= new JTextField(10);   
  38.         final JTextField output=new JTextField(25);   
  39.         JButton btnn=new JButton("Welcome");   
  40.         add(prompt);   
  41.         add(input);   
  42.         add(output);   
  43.         add(btnn);   
  44.         btnn.addActionListener(   
  45.         new    
  46.         ActionListener()   
  47.         {   
  48.             public void actionPerformed(ActionEvent event)   
  49.             {   
  50.                 String s=input.getText();   
  51.                 output.setText("Hello"+s+",欢迎参加JAVA考试");   
  52.             }   
  53.                
  54.         });   
  55.     }      
  56. }  

 

  • Welcome.jar (2.8 KB)
  • 描述: APPLICATION窗口:
  • 下载次数: 2
评论
chenchuxin 2008-03-26
/**
 * AWT Sample application
 *
 * @author 
 * @version 1.00 08/03/26
 */
public class AAA {
    
    public static void main(String[] args) {
        // Create application frame.
        AAAFrame frame = new AAAFrame();
        
        // Show frame
        frame.setVisible(true);
    }
}


import java.awt.*;
import java.awt.event.*;

/**
 * Sample application using Frame.
 *
 * @author 
 * @version 1.00 08/03/26
 */
public class AAAFrame extends Frame {
    
    /**
     * The constructor.
     */  
     public AAAFrame() {
                
        MenuBar menuBar = new MenuBar();
        Menu menuFile = new Menu();
        MenuItem menuFileExit = new MenuItem();
        
        menuFile.setLabel("File");
        menuFileExit.setLabel("Exit");
        
        // Add action listener.for the menu button
        menuFileExit.addActionListener
        (
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    AAAFrame.this.windowClosed();
                }
            }
        ); 
        menuFile.add(menuFileExit);
        menuBar.add(menuFile);
        
        setTitle("AAA");
        setMenuBar(menuBar);
        setSize(new Dimension(400, 400));
        
        // Add window listener.
        this.addWindowListener
        (
            new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    AAAFrame.this.windowClosed();
                }
            }
        );  
    }
    
    
    /**
     * Shutdown procedure when run as an application.
     */
    protected void windowClosed() {
    	
    	// TODO: Check if it is safe to close the application
    	
        // Exit application.
        System.exit(0);
    }
}

chenchuxin 2007-12-12
import java.awt.*;
import java.applet.*;
public class TimeFlies extends Applet {
public void paint(Graphics g){
g.drawString("光阴似箭",25,25);
}

}
发表评论

您还没有登录,请登录后发表评论

chenchuxin
搜索本博客
存档
最新评论