/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mysort;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/*
* @author Administrator
*/
public class Main{
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
int finish = 1;
int finish1 = 1;
int array[]=null;
Scanner scanner = new Scanner(System.in);
int choice;
System.out.println("请选择输入数据的方法:");
System.out.println("***1、键盘输入数据***");
System.out.println("***2、读取数组数据***");
System.out.println("***3、退出***");
while(finish !=0)
{
choice = scanner.nextInt();
switch( choice ){
case 1:
Example1 a = new Example1();
array = a.data( array );
finish = 0;
break;
case 2:
Example2 b = new Example2();
array = b.getdataFromFile(array);
finish = 0;
break;
case 3:
System.out.println("***欢迎下次是使用***");
finish = 0;
break;
default:
System.out.println("***数据输入有误,请重新输入***");
continue;
}
}
sort:{
System.out.println( "请选择你需要的排序方法:");
System.out.println( "***1、冒泡排序法***");
System.out.println( "***2、快速排序法***");
System.out.println( "***3、选择排序法***");
System.out.println( "***4、退出***");
while(finish1 !=0 )
{
int s= scanner.nextInt();
switch(s)
{
case 1:
A1 a1=new A1(array) ;
a1.sort();
a1.dosort();
a1.result();
a1.showtime();
a1.showdata();
break;
case 2:
A2 a2=new A2(array);
a2.sort();
a2.dosort( );
a2.result();
a2.showtime();
a2.showdata();
break;
case 3:
A3 a3=new A3(array);
a3.sort();
a3.dosort();
a3.result();
a3.showtime();
a3.showdata();
break;
case 4:
finish1 = 0;
System.out.println("欢迎下次再来!");
break;
default:
System.out.println("***数据输入有误,请重新输入***");
continue;
}
}
}
}
class ui extends JFrame implements ActionListener {
JLabel wdataLabel;
JLabel dataLabel_bubble,showTimeLabel_bubble,sExchangeLabel_bubble,sCompareLabel_bubble,sProbeLabel_bubble;
JLabel dataLabel_select,showTimeLabel_select,sExchangeLabel_select,sCompareLabel_select,sProbeLabel_select;
JLabel dataLabel_quick,showTimeLabel_quick,sExchangeLabel_quick,sCompareLabel_quick,sProbeLabel_quick;
JTextField wdataTxt;
JTextField dataTxt_bubble,showTimeTxt_bubble,sExchangeTxt_bubble,sCompareTxt_bubble,sProbeTxt_bubble;
JTextField dataTxt_select,showTimeTxt_select,sExchangeTxt_select,sCompareTxt_select,sProbeTxt_select;
JTextField dataTxt_quick,showTimeTxt_quick,sExchangeTxt_quick,sCompareTxt_quick,sProbeTxt_quick;
JButton keytoinBtn,filetoinBtn,bubbleBtn,selectBtn,quickBtn;
JPanel topPanel,midPanel;
GridBagLayout layout;
GridBagConstraints constraints;
public ui(){
super("排序功能比较");
Container c = getContentPane();
c.setLayout(new BorderLayout());
layout = new GridBagLayout();
midPanel = new JPanel(layout);
topPanel = new JPanel(layout);
setComponent();
c.add ( topPanel,BorderLayout.CENTER );
c.add ( midPanel,BorderLayout.CENTER );
pack();
setVisible(true);
}
public void setComponent(){
constraints = new GridBagConstraints();
wdataLabel = new JLabel("待排序数据:");
wdataTxt = new JTextField();
addComponent( wdataLabel,0,0,1,3);
addComponent(wdataTxt,0,3,1,8);
dataLabel_bubble = new JLabel("排序结果:");
dataTxt_bubble = new JTextField();
addComponent( dataLabel_bubble,3,0,1,3);
addComponent(dataTxt_bubble,3,3,1,8);
showTimeLabel_bubble = new JLabel("排序时间:");
showTimeTxt_bubble = new JTextField();
addComponent( showTimeLabel_bubble,4,0,1,3);
addComponent(showTimeTxt_bubble,4,3,1,4);
sExchangeLabel_bubble = new JLabel("交换次数:");
sExchangeTxt_bubble = new JTextField();
addComponent( sExchangeLabel_bubble,5,0,1,3);
addComponent( sExchangeTxt_bubble,5,3,1,4 );
sCompareLabel_bubble = new JLabel("比较次数:");
sCompareTxt_bubble = new JTextField();
addComponent( sCompareLabel_bubble,6,0,1,3 );
addComponent( sCompareTxt_bubble,6,3,1,4 );
sProbeLabel_bubble = new JLabel("探测次数:");
sProbeTxt_bubble = new JTextField();
addComponent( sProbeLabel_bubble,7,0,1,3 );
addComponent( sProbeTxt_bubble,7,3,1,4 );
dataLabel_select = new JLabel("排序结果:");
dataTxt_select = new JTextField();
addComponent( dataLabel_select,3,10,1,3);
addComponent(dataTxt_select,3,13,1,9);
showTimeLabel_select = new JLabel("排序时间:");
showTimeTxt_select = new JTextField();
addComponent( showTimeLabel_select,4,10,1,3);
addComponent(showTimeTxt_select,4,13,1,4);
sExchangeLabel_select = new JLabel("交换次数:");
sExchangeTxt_select = new JTextField();
addComponent( sExchangeLabel_select,5,10,1,3 );
addComponent( sExchangeTxt_select,5,13,1,4 );
sCompareLabel_select = new JLabel("比较次数:");
sCompareTxt_select = new JTextField();
addComponent( sCompareLabel_select,6,10,1,3 );
addComponent( sCompareTxt_select,6,13,1,4 );
sProbeLabel_select = new JLabel("探测次数:");
sProbeTxt_select = new JTextField();
addComponent( sProbeLabel_select,7,10,1,3 );
addComponent( sProbeTxt_select,7,13,1,4 );
dataLabel_quick = new JLabel("排序结果:");
dataTxt_quick = new JTextField();
addComponent( dataLabel_quick,3,20,1,3);
addComponent(dataTxt_quick,3,23,1,8);
showTimeLabel_quick = new JLabel("排序时间:");
showTimeTxt_quick = new JTextField();
addComponent( showTimeLabel_quick,4,20,1,3 );
addComponent(showTimeTxt_quick,4,23,1,4);
sExchangeLabel_quick = new JLabel("交换次数:");
sExchangeTxt_quick = new JTextField();
addComponent( sExchangeLabel_quick,5,20,1,3 );
addComponent( sExchangeTxt