⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wekagui.java

📁 基于weka平台的数据挖掘方法
💻 JAVA
字号:
import weka.gui.*;
import weka.core.*;
import weka.classifiers.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.reflect.*;
import java.beans.*;
import java.util.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import weka.gui.GenericObjectEditor;

class wekagui extends JFrame{
	public static Object oo=new weka.classifiers.functions.SMO();
	public static Object back_oo=null;
	 final JTextField jtf1;
	 JTextField jtf2,jtf3,jtf4,jtf5;
	JPanel jp1,jp11,jp12,jp2,jp3,jp4,jp21,jp22,jp31,jp32;
	JLabel jl,jl2,jl3,jl4,jl5,jl6;
	JButton jb2,jb3,jb4;
	JButton jbchoose;
	FileReader fd;
	FileWriter fw;
	String classmethod;
	 String method="weka.classifiers.functions.SMO";

	wekagui(){
		super("SSiCP-Second Step");
		jl=new JLabel("Method:");
		jbchoose=new JButton("Choose Method");
		jtf1=new JTextField(oo.getClass().getName(),20);
		jp1=new JPanel(new BorderLayout());
		jp11=new JPanel();
		jp12=new JPanel();
		jp2=new JPanel();
		jp3=new JPanel();
		jp4=new JPanel();
		jp21=new JPanel();
		jp22=new JPanel();
		jp31=new JPanel();
		jp32=new JPanel();

		jb4=new JButton("Calculate");

		jl2=new JLabel("input");
		jl3=new JLabel("output");
		jl4=new JLabel("Fold:");
		jl5=new JLabel("Random Seed:");
		jl6=new JLabel("Cross-Validation:");
		jtf2=new JTextField(10);
		jtf3=new JTextField(10);
		jtf4=new JTextField("10",5);
		jtf5=new JTextField("1",3);
		jb2=new JButton("input");
		jb3=new JButton("output");

		jbchoose.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
						back_oo=oo;						
						GenericObjectEditor ce = new GenericObjectEditor(true);
     					ce.setClassType(weka.classifiers.Classifier.class);
   					    ce.setValue(oo);
   						PropertyDialog pd = new PropertyDialog(ce, 100, 100);
   						
   						((GenericObjectEditor.GOEPanel)ce.getCustomEditor()).addCancelListener(new ActionListener(){
   								public void actionPerformed(ActionEvent e){
		   							jtf1.setText(back_oo.getClass().getName());
		   							oo=back_oo;
   								}
   							});
   							
   						((GenericObjectEditor.GOEPanel)ce.getCustomEditor()).addOkListener(new ActionListener(){
   								public void actionPerformed(ActionEvent e){
   									jtf1.setText(oo.getClass().getName());	
   									back_oo=oo;   									
   								}
   							});
   							
   						ce.addPropertyChangeListener(new PropertyChangeListener(){
   								public void propertyChange(PropertyChangeEvent evt){
   										try {
   											GenericObjectEditor goe=(GenericObjectEditor)evt.getSource();
   											oo=goe.getValue();
										  }
										  catch (Exception ex) {
										  }
   								}
   							});
				}
			});



		jb4.addActionListener(new HandleAction());

		setSize(600,500);
		setLocation(200,200);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setLayout(new GridLayout(2,2));
		getContentPane().add(jp1);
		getContentPane().add(jp2);
		getContentPane().add(jp3);
		getContentPane().add(jp4);
		jp1.add(jp11,BorderLayout.NORTH);
		jp1.add(jp12,BorderLayout.CENTER);
		jp11.add(jl);
		jp11.add(jtf1);
		jp12.add(jbchoose);
		jp21.add(jl2);
		jp21.add(jtf2);
		jp21.add(jb2);
		jp22.add(jl3);
		jp22.add(jtf3);
		jp22.add(jb3);
		jp2.add(jp21);
		jp2.add(jp22);
		jp31.add(jl6);
		jp32.add(jl4);
		jp32.add(jtf4);
		jp32.add(jl5);
		jp32.add(jtf5);
		jp3.add(jp31);
		jp3.add(jp32);
		jp4.add(jb4);

		jb2.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
				JFileChooser jfc=new JFileChooser();
				arffFileFilter ff=new arffFileFilter();
				jfc.setFileFilter(ff);
				jfc.showOpenDialog(null);
				File f=jfc.getSelectedFile();
				if(f!=null)
				jtf2.setText(f.getPath());
			}	
			
		});
		jb3.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
				JFileChooser jfc=new JFileChooser();
				arffFileFilter ff=new arffFileFilter();
				JFrame jf=(JFrame)((JButton)e.getSource()).getFocusCycleRootAncestor();
				jfc.setFileFilter(ff);
				if(jfc.showSaveDialog(null)==JFileChooser.APPROVE_OPTION)
				{
					File f=jfc.getSelectedFile();
					if(f.exists())
					{
						JDialog jd=new JDialog(jf,"Warning",true);
						JPanel jp1=new JPanel();
						JPanel jp2=new JPanel();
						JLabel id=new JLabel("File exist!");
						JButton jbtn=new JButton("I know");
						jp1.add(id);
						jp2.add(jbtn);
						jbtn.addActionListener(new ActionListener(){
							public void actionPerformed(ActionEvent e){
								((JDialog)((JButton)e.getSource()).getFocusCycleRootAncestor()).dispose();
							}
							});
						jd.add(jp1);
						jd.add(jp2,BorderLayout.SOUTH);
						jd.setLocation(300,300);
						jd.setSize(200,100);
						jd.setVisible(true);
						
					}
					String ss=f.getPath();
					if(!ss.toLowerCase().endsWith(".arff"))
						ss=ss+".arff";
					jtf3.setText(ss);
				}
			}	
			
		});		
		setVisible(true);

	}
	public static void main(String arg[]){
		new wekagui();
	}
}
class HandleAction implements ActionListener{
	public void actionPerformed(ActionEvent e){
		wekagui ds=(wekagui)((JButton)e.getSource()).getFocusCycleRootAncestor();
		if(ds.jtf2.getText().equals("") || ds.jtf3.getText().equals("") ||/* ds.jcb1.getSelectedIndex()==0 || ds.jcb2.getSelectedIndex()==0 ||*/ ds.jtf4.getText().equals("") || ds.jtf5.getText().equals("")){
			JOptionPane.showMessageDialog(ds,"Some Information is Empty or not Select !","Warning",JOptionPane.INFORMATION_MESSAGE);
			return ;
		}
	
		 if(e.getActionCommand().equals("Calculate")){
				
			String infile=ds.jtf2.getText();
			String outfile=ds.jtf3.getText();
			int m_fold=Integer.parseInt(ds.jtf4.getText());
			int seed=Integer.parseInt(ds.jtf5.getText());
			
		if(JOptionPane.OK_OPTION==JOptionPane.showConfirmDialog(null,"Begin Calculate?","Warning",JOptionPane.OK_CANCEL_OPTION)){
		
				DataMining dt=new DataMining(infile,outfile,(Classifier)wekagui.oo,m_fold,seed);
		
				dt.setClassIndex();
			try {
				Thread th=new Thread(dt);
                     th.start();  
		    }
		    catch (Exception ex) {
		    	ex.printStackTrace();
		    }
		}	
		}
	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -