import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class Frame1 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JButton jButton1 = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JList jList1 = new JList();
JButton jButton2 = new JButton();
Vector list = new Vector(); //Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setText("jButton1");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jButton2.setText("jButton2");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
contentPane.add(jButton1, BorderLayout.NORTH);
contentPane.add(jScrollPane1, BorderLayout.CENTER);
contentPane.add(jButton2, BorderLayout.SOUTH);
jScrollPane1.getViewport().add(jList1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
} void jButton1_actionPerformed(ActionEvent e) {
jList1.removeSelectionInterval(0,1);
list.clear();
jList1.setListData(list);
jList1.updateUI();
} void jButton2_actionPerformed(ActionEvent e) {
for(int i = 0;i < 10;i ++) {
String a = Integer.toString(i);
list.add(a);
}
jList1.setListData(list);
}
public static void main(String[] args){
Frame1 f = new Frame1();
f.pack();
f.setVisible(true);
}
}class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
import java.awt.event.*;
import javax.swing.*;
import java.util.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class Frame1 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JButton jButton1 = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JList jList1 = new JList();
JButton jButton2 = new JButton();
Vector list = new Vector(); //Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setText("jButton1");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jButton2.setText("jButton2");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
contentPane.add(jButton1, BorderLayout.NORTH);
contentPane.add(jScrollPane1, BorderLayout.CENTER);
contentPane.add(jButton2, BorderLayout.SOUTH);
jScrollPane1.getViewport().add(jList1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
} void jButton1_actionPerformed(ActionEvent e) {
jList1.removeSelectionInterval(0,1);
list.clear();
jList1.setListData(list);
jList1.updateUI();
} void jButton2_actionPerformed(ActionEvent e) {
for(int i = 0;i < 10;i ++) {
String a = Integer.toString(i);
list.add(a);
}
jList1.setListData(list);
}
public static void main(String[] args){
Frame1 f = new Frame1();
f.pack();
f.setVisible(true);
}
}class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货