//AWT的示例
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class test1
extends JFrame {
static java.util.Random rnd = new java.util.Random(); JButton jButton1 = new JButton();
java.awt.List list1 = new java.awt.List();
public static void main(String[] args) {
new test1().show();
} public test1() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} private void jbInit() throws Exception {
for (int i = 0; i < 30; i++) {
list1.add(Integer.toString(rnd.nextInt(100)));
}
this.setSize(new Dimension(253, 345));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(null); jButton1.setBounds(new Rectangle(83, 238, 83, 30));
jButton1.setText("排序");
jButton1.addActionListener(new test1_jButton1_actionAdapter(this)); list1.setBounds(new Rectangle(53, 23, 142, 163));
this.getContentPane().add(jButton1, null);
this.getContentPane().add(list1, null);
} void jButton1_actionPerformed(ActionEvent e) {
String tmp;
for (int j = 0; j < list1.getItemCount(); j++) {
for (int i = 0; i < list1.getItemCount() - j - 1; i++) {
if (Integer.parseInt(list1.getItem(i)) >
Integer.parseInt(list1.getItem(i + 1))) {
tmp = list1.getItem(i);
list1.replaceItem(list1.getItem(i + 1), i);
list1.replaceItem(tmp, i + 1);
}
}
} } class test1_jButton1_actionAdapter
implements java.awt.event.ActionListener {
test1 adaptee; test1_jButton1_actionAdapter(test1 adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
}
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class test1
extends JFrame {
static java.util.Random rnd = new java.util.Random(); JButton jButton1 = new JButton();
java.awt.List list1 = new java.awt.List();
public static void main(String[] args) {
new test1().show();
} public test1() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} private void jbInit() throws Exception {
for (int i = 0; i < 30; i++) {
list1.add(Integer.toString(rnd.nextInt(100)));
}
this.setSize(new Dimension(253, 345));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(null); jButton1.setBounds(new Rectangle(83, 238, 83, 30));
jButton1.setText("排序");
jButton1.addActionListener(new test1_jButton1_actionAdapter(this)); list1.setBounds(new Rectangle(53, 23, 142, 163));
this.getContentPane().add(jButton1, null);
this.getContentPane().add(list1, null);
} void jButton1_actionPerformed(ActionEvent e) {
String tmp;
for (int j = 0; j < list1.getItemCount(); j++) {
for (int i = 0; i < list1.getItemCount() - j - 1; i++) {
if (Integer.parseInt(list1.getItem(i)) >
Integer.parseInt(list1.getItem(i + 1))) {
tmp = list1.getItem(i);
list1.replaceItem(list1.getItem(i + 1), i);
list1.replaceItem(tmp, i + 1);
}
}
} } class test1_jButton1_actionAdapter
implements java.awt.event.ActionListener {
test1 adaptee; test1_jButton1_actionAdapter(test1 adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
}
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class test
extends JFrame {
static java.util.Random rnd = new java.util.Random();
Vector arr = new Vector(30);
JList jList1 = new JList();
JScrollPane jScrollPane1 = new JScrollPane();
JButton jButton1 = new JButton();
public static void main(String[] args) {
new test().show();
} public test() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} private void jbInit() throws Exception {
for (int i = 0; i < 30; i++) {
arr.addElement(Integer.toString(rnd.nextInt(100)));
}
this.setSize(new Dimension(253, 345));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(null);
jScrollPane1.setBounds(new Rectangle(58, 55, 139, 154));
jButton1.setBounds(new Rectangle(83, 238, 83, 30));
jButton1.setText("排序");
jButton1.addActionListener(new test_jButton1_actionAdapter(this));
this.getContentPane().add(jScrollPane1, null);
this.getContentPane().add(jButton1, null);
jScrollPane1.getViewport().add(jList1, null);
jList1.setListData(arr);
} void jButton1_actionPerformed(ActionEvent e) {
String tmp;
for (int j = 0; j < arr.size(); j++) {
for (int i = 0; i < arr.size() - j - 1; i++) {
if (Integer.parseInt(arr.elementAt(i).toString()) >
Integer.parseInt(arr.elementAt(i + 1).toString())) {
tmp = arr.elementAt(i).toString();
arr.setElementAt(arr.elementAt(i + 1), i);
arr.setElementAt(tmp, i + 1);
}
}
}
this.jList1.setListData(arr);
}
}class test_jButton1_actionAdapter
implements java.awt.event.ActionListener {
test adaptee;
test_jButton1_actionAdapter(test adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}