RSS

Java Applet 3

12 11月

Java Applet3  /My Document/Develop/Java/Applet3.zip

Java Applet3

 
import java.awt.*;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JTable;
import javax.swing.JButton;

/*
<applet code="JApplet3.class" width="400" height="100">
</applet>
 */

public class JApplet3 extends JApplet {
 private static final long serialVersionUID = 1L;
 private JPanel jContentPane = null;
 private JPanel jPanel = null;
 private JPanel jPanel1 = null;
 private JLabel jLabel = null;
 private JTable jTable = null;
 private JButton jButton = null;
 /**
  * This is the default constructor
  */
 public JApplet3() {
  super();
 }

 /**
  * This method initializes this
  *
  * @return void
  */
 public void init() {
  this.setSize(300, 200);
  this.setContentPane(getJContentPane());
 }

 /**
  * 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(getJButton(), null);
  }
  return jPanel;
 }

 /**
  * This method initializes jPanel1 
  *  
  * @return javax.swing.JPanel 
  */
 private JPanel getJPanel1() {
  if (jPanel1 == null) {
   GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
   gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
   gridBagConstraints1.gridy = 1;
   gridBagConstraints1.weightx = 1.0;
   gridBagConstraints1.weighty = 1.0;
   gridBagConstraints1.gridx = 0;
   GridBagConstraints gridBagConstraints = new GridBagConstraints();
   gridBagConstraints.gridx = 0;
   gridBagConstraints.gridy = 0;
   jLabel = new JLabel();
   jLabel.setText("JLabel");
   jPanel1 = new JPanel();
   jPanel1.setLayout(new GridBagLayout());
   jPanel1.add(jLabel, gridBagConstraints);
   jPanel1.add(getJTable(), gridBagConstraints1);
  }
  return jPanel1;
 }

 /**
  * This method initializes jTable 
  *  
  * @return javax.swing.JTable 
  */
 private JTable getJTable() {
  String columnNames[] = {"A", "B", "C", "D", "E"};
  String tableData[][] = {
    {"A1", "B1", "C1", "D1", "E1"},
    {"A2", "B2", "C2", "D2", "E2"},
    {"A3", "B3", "C3", "D3", "E3"},
    {"A4", "B4", "C4", "D4", "E4"},
   };
  if (jTable == null) {
   jTable = new JTable(tableData, columnNames);
  }
  jTable.setColumnSelectionAllowed(true);
  jTable.addMouseListener(new java.awt.event.MouseListener() {
   public void mouseClicked(java.awt.event.MouseEvent e) {
    int col = jTable.getSelectedColumn();
    int row = jTable.getSelectedRow();
    String val = (String)jTable.getValueAt(row, col);
    jLabel.setText("row=" + row + ", column=" + col + ", value=" + val);
   }
   public void mousePressed(java.awt.event.MouseEvent e) {
   }
   public void mouseReleased(java.awt.event.MouseEvent e) {
   }
   public void mouseEntered(java.awt.event.MouseEvent e) {
   }
   public void mouseExited(java.awt.event.MouseEvent e) {
   }
  });
  return jTable;
 }

 /**
  * This method initializes jButton 
  *  
  * @return javax.swing.JButton 
  */
 private JButton getJButton() {
  if (jButton == null) {
   jButton = new JButton();
   jButton.setText("edit");
   jButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent e) {
     editCell();
    }
   });
  }
  return jButton;
 }

 private void editCell() {
  int row = jTable.getSelectedRow();
  int col = jTable.getSelectedColumn();
  jTable.editCellAt(row, col);  
 }

}

 

実行 appletviewer JApplet3.java

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

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

 

タグ:

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