RSS

Java Applet 5

12 11月

Java Applet 5   /My Document/Develop/Java/Applet5.zip

Java Applet 5

import java.awt.*;
import javax.swing.*;
/*
 <applet code="JApplet5.class" name="JApplet5" width="400" height="320" align="center">
  <param name="gif1" value="BACK_1.GIF"/>
  <param name="gif2" value="BACK_2.GIF"/>
  <param name="gif3" value="BACK_3.GIF"/>
  <param name="gif4" value="BACK_4.GIF"/>
  <param name="gif5" value="BACK_5.GIF"/>
 </applet>
 */
public class JApplet5 extends JApplet {
 private static final long serialVersionUID = 1L;
 private JPanel jContentPane = null;
 private JPanel jPanel = null;
 private JPanel jPanel1 = null;
 private JComboBox jComboBox = null;
 private Image images[] = new Image[5];
 private int selectedIndex = 0;
 /**
  * This is the default constructor
  */
 public JApplet5() {
  super();
 }
 /**
  * This method initializes this
  *
  * @return void
  */
 public void init() {
  this.setSize(300, 200);
  this.setContentPane(getJContentPane());
  this.images[0] = this.getImage(this.getDocumentBase(), this.getParameter("gif1"));
  this.images[1] = this.getImage(this.getDocumentBase(), this.getParameter("gif2"));
  this.images[2] = this.getImage(this.getDocumentBase(), this.getParameter("gif3"));
  this.images[3] = this.getImage(this.getDocumentBase(), this.getParameter("gif4"));
  this.images[4] = this.getImage(this.getDocumentBase(), this.getParameter("gif5"));
  this.jComboBox.addItem("IMAGE1");
  this.jComboBox.addItem("IMAGE2");
  this.jComboBox.addItem("IMAGE3");
  this.jComboBox.addItem("IMAGE4");
  this.jComboBox.addItem("IMAGE5");
 }
 /**
  * This method initializes jContentPane
  *
  * @return javax.swing.JPanel
  */
 private JPanel getJContentPane() {
  if (jContentPane == null) {
   jContentPane = new JPanel();
   jContentPane.setLayout(new BorderLayout());
   jContentPane.add(getJPanel(), java.awt.BorderLayout.SOUTH);
   jContentPane.add(getJPanel1(), java.awt.BorderLayout.CENTER);
  }
  return jContentPane;
 }
 /**
  * This method initializes jPanel 
  *  
  * @return javax.swing.JPanel 
  */
 private JPanel getJPanel() {
  if (jPanel == null) {
   jPanel = new JPanel();
   jPanel.add(getJComboBox(), null);
  }
  return jPanel;
 }
 /**
  * This method initializes jPanel1 
  *  
  * @return javax.swing.JPanel 
  */
 private JPanel getJPanel1() {
  if (jPanel1 == null) {
   jPanel1 = new JPanel();
  }
  return jPanel1;
 }
 /**
  * This method initializes jComboBox 
  *  
  * @return javax.swing.JComboBox 
  */
 private JComboBox getJComboBox() {
  if (jComboBox == null) {
   jComboBox = new JComboBox();
   jComboBox.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent e) {
     comboboxSelecttionChanged();
    }
   });
  }
  return jComboBox;
 }
 public void paint(Graphics g)
 {
  super.paint(g);

  g.drawImage(this.images[this.selectedIndex], 8, 8, this);
 }

 private void comboboxSelecttionChanged() {
  this.selectedIndex = jComboBox.getSelectedIndex();
  repaint();
 }
}

 

実行 appletviewer JApplet5.java

 
Java Applet 5 はコメントを受け付けていません。

投稿者: : 2010/11/12 投稿先 Java

 

タグ:

コメントは受け付けていません。