📄 inputframe.java
字号:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.io.*;
import javax.swing.filechooser.*;
class InputFrame extends JFrame implements ActionListener{
JLabel lenterNoOfEle=null,lenterFileName=null,title=null;
JTextField tenterNoOfEle=null,tenterFileName=null;
JButton chooseAlgm=null,exit=null,openDialog=null;
File file=null;
JFileChooser fc;
int noOfClusters;
boolean flag;
Vector dataPoints=null;
int size;
public InputFrame(){
super("WELCOME WINDOW");
title=new JLabel("WELCOME TO CLUSTERING ALGORITHMS");
title.setFont( new Font("Garamond",Font.BOLD,28));
lenterNoOfEle=new JLabel("Enter No.Of Clusters U Want");
lenterFileName=new JLabel("Enter The File Name With Full Path:");
tenterNoOfEle=new JTextField();
tenterFileName=new JTextField();
chooseAlgm=new JButton("Choose Algorithm");
fc = new JFileChooser();
openDialog=new JButton("Browse...");
exit=new JButton("Exit");
flag=false;
size=0;
Container c = getContentPane();
c.setLayout(null);
title.setBounds(200,50,700,100);
lenterFileName.setBounds(350,200,300,30);
tenterFileName.setBounds(350,230,300,30);
openDialog.setBounds(600,270,100,30);
lenterNoOfEle.setBounds(350,325,200,30);
tenterNoOfEle.setBounds(350,365,200,30);
chooseAlgm.setBounds(350,500,150,50);
exit.setBounds(520,500,150,50);
c.setBackground(new Color(255,200,218));//Color.lightGray);
c.add(title);
c.add(lenterFileName);
c.add(tenterFileName);
c.add(openDialog);
c.add(lenterNoOfEle);
c.add(tenterNoOfEle);
c.add(chooseAlgm);
c.add(exit);
openDialog.addActionListener(this);
chooseAlgm.addActionListener(this);
exit.addActionListener(this);
setSize(1025,750);
setVisible(true);
}
public int readData(){
System.out.println("file is::"+file.getAbsolutePath());
ReadFile rf=new ReadFile(file.getAbsolutePath());
noOfClusters=Integer.parseInt(tenterNoOfEle.getText());
System.out.println("No of Clusters Are: "+noOfClusters);
dataPoints=rf.getDataPoints();
System.out.println("file name is: "+tenterFileName.getText());
System.out.println("No of DataPoints Are: "+dataPoints.size());
return (dataPoints.size());
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==exit){
System.exit(0);
}else if(ae.getSource()==openDialog){
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION){
file = fc.getSelectedFile();
System.out.println("Opening: " + file.getAbsolutePath() + ".\n" );
tenterFileName.setText(file.getAbsolutePath());
}
}else if(ae.getSource()==chooseAlgm){
File f=new File(tenterFileName.getText());
if ( file==null){
file=f;
}
if( !file.isFile() ) {
JOptionPane.showMessageDialog(null,"Invalid FileName","Invalid",JOptionPane.INFORMATION_MESSAGE);
}else{
System.out.println("File is:"+file.getAbsolutePath());
int tsize=Integer.parseInt(tenterNoOfEle.getText());
size=readData();
if( size==0 || tsize <= 0 || tsize>size ){
System.out.println("size is: "+size+" tsize is: "+tsize);
dataPoints.removeAllElements();
JOptionPane.showMessageDialog(null,"Invalid No of clusters","Invalid",JOptionPane.INFORMATION_MESSAGE);
}else {
System.out.println("else size is: "+size+" tsize is: "+tsize);
ChooseAlgm ca=new ChooseAlgm(noOfClusters,dataPoints);
}
}
}
}
public static void main(String []args){
InputFrame if1=new InputFrame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -