資源簡介
實現了選擇排序 插入排序 冒泡排序等三種算法,利用javaGUI界面實現動態演示(動態用線程實現)

代碼片段和文件信息
package?Gui;
import?java.awt.*;
import?java.awt.event.*;
import?java.io.FileNotFoundException;
import?javax.swing.*;
import?Input.*;
import?SortMeth.*;
public?class?GuiTest?extends?Jframe
{
?
private?JButton[]?start;
private??JLabel[]n;
????private?int[]?v;
????private?JButton?reset;
????private?JLabel?showsort;
????private?JLabel?show;
public?GuiTest()?
{
super(“排序演示“);
this.getContentPane().setLayout(null);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.setSize(650200);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setAlwaysOnTop(true);
try{
doLable();
}
catch(Exception?e)?{}
//start.addActionListener(new?ActionListener(){public?void?actionPerformed(ActionEvent?e){sort(n);}});
doButton();
}//End?of?GuiTest()
public?void?doLable()
{
try{
FileInputClass?fin=new?FileInputClass();
v=new?int[fin.getN()];
v=fin.getArray();
}
catch(Exception?e){}
JLabel?l?=?new?JLabel(“待排序的數字:“);//
l.setBounds(306012525);
l.setFont(new?Font(““Font.BOLD18));
add(l);//Label:待排序的數字
showsort=new?JLabel();
showsort.setFont(new?Font(““Font.BOLD18));
showsort.setBounds(370?60?300?25);
showsort.setVisible(false);
add(showsort);
show=new?JLabel();
show.setBounds(3709030025);
show.setFont(new?Font(““Font.BOLD18));
show.setVisible(false);
add(show);
try
{
FileInputClass?fin=new?FileInputClass();
n=new?JLabel[fin.getN()];
int?left=0w=40offx=0offy=95;
for(int?i=0;?i {
n[i]=new?JLabel();
n[i].setFont(new?Font(““Font.BOLD18));
n[i].setForeground(Color.gray);
n[i].setHorizontalAlignment(JLabel.CENTER);
n[i].setText(String.valueOf(fin.getArray()[i]));
n[i].setSize(w20);
n[i].setLocation((left+=w)+offxoffy);
add(n[i]);
}//for
}//try
catch(Exception?e)
?{
?}
}//end?of?doLabel
public?void?doButton()
{
int?offx=60;
reset?=?new?JButton();
reset.setBounds(50?120?120?25);
reset.setText(“重置“);
reset.setFont(new?Font(““Font.BOLD18));//重置
add(reset);
reset.addActionListener(new?ActionListener(){public?void?actionPerformed(ActionEvent?e){reset();}});
start?=?new?JButton[3];
for(int?i=0;i<3;i++)
{
start[i]=new?JButton();
start[i].setBounds(offx1812025);
start[i].setFont(new?Font(““Font.BOLD18));
offx=offx+180;
add(start[i]);
}
start[0].setText(“選擇排序“);start[1].setText(“插入排序“);start[2].setText(“冒泡排序“);
//JButtonHandler?h=new?JButtonHandler();
//start[0].addActionListener(h);
start[0].addActionListener(new?ActionListener(){public?void?actionPerformed(ActionEvent?e){final?SortingMeth?sl=new?SeletionSort(v);sl.dosort(nshowsortshow);}});//匿名內部類。final
start[1].addActionListener(new?ActionListener(){public?void?actionPerformed(ActionEvent?e){final?SortingMeth?is=new?InsertSort(v);is.dos
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????226??2010-05-05?16:38??Sortshow\Sortshow\.classpath
?????文件????????384??2010-05-05?16:38??Sortshow\Sortshow\.project
?????文件????????637??2010-06-11?19:30??Sortshow\Sortshow\Gui\GuiTest$1.class
?????文件???????1030??2010-06-11?19:30??Sortshow\Sortshow\Gui\GuiTest$2.class
?????文件???????1028??2010-06-11?19:30??Sortshow\Sortshow\Gui\GuiTest$3.class
?????文件???????1028??2010-06-11?19:30??Sortshow\Sortshow\Gui\GuiTest$4.class
?????文件???????3896??2010-06-11?19:30??Sortshow\Sortshow\Gui\GuiTest.class
?????文件???????3512??2010-06-10?19:15??Sortshow\Sortshow\Gui\GuiTest.java
?????文件???????1928??2010-06-11?19:30??Sortshow\Sortshow\Input\FileInputClass.class
?????文件???????1184??2010-06-06?01:28??Sortshow\Sortshow\Input\FileInputClass.java
?????文件????????938??2010-06-11?19:30??Sortshow\Sortshow\Input\InputClass.class
?????文件???????1292??2010-06-02?00:27??Sortshow\Sortshow\Input\InputClass.java
?????文件???????2785??2010-06-12?15:29??Sortshow\Sortshow\SortMeth\BubbleSort$1.class
?????文件????????738??2010-06-12?15:29??Sortshow\Sortshow\SortMeth\BubbleSort.class
?????文件???????2138??2010-06-12?15:29??Sortshow\Sortshow\SortMeth\BubbleSort.java
?????文件???????2813??2010-06-11?19:30??Sortshow\Sortshow\SortMeth\InsertSort$1.class
?????文件????????738??2010-06-11?19:30??Sortshow\Sortshow\SortMeth\InsertSort.class
?????文件???????2224??2010-06-11?00:18??Sortshow\Sortshow\SortMeth\InsertSort.java
?????文件???????2708??2010-06-11?19:30??Sortshow\Sortshow\SortMeth\SeletionSort$1.class
?????文件????????748??2010-06-11?19:30??Sortshow\Sortshow\SortMeth\SeletionSort.class
?????文件???????2114??2010-06-10?16:54??Sortshow\Sortshow\SortMeth\SeletionSort.java
?????文件???????3096??2010-06-11?19:30??Sortshow\Sortshow\SortMeth\SortingMeth.class
?????文件???????2460??2010-06-11?00:19??Sortshow\Sortshow\SortMeth\SortingMeth.java
?????文件?????????23??2010-06-09?10:30??Sortshow\Sortshow\test.txt
?????文件??????21879??2010-06-10?18:55??Sortshow\Sortshow.rar
?????目錄??????????0??2010-08-07?13:03??Sortshow\Sortshow\Gui
?????目錄??????????0??2010-08-07?13:03??Sortshow\Sortshow\Input
?????目錄??????????0??2010-08-07?13:03??Sortshow\Sortshow\SortMeth
?????目錄??????????0??2010-09-04?16:24??Sortshow\Sortshow
?????目錄??????????0??2010-08-07?12:59??Sortshow
............此處省略3個文件信息
- 上一篇:成績管理系統android
- 下一篇:java進銷存系統
評論
共有 條評論