以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Web挖掘技术 』   (http://bbs.xml.org.cn/list.asp?boardid=69)
----  weka源码 之 GUIChooser.java  (http://bbs.xml.org.cn/dispbbs.asp?boardid=69&rootid=&id=45291)


--  作者:DMman
--  发布时间:4/12/2007 8:53:00 AM

--  weka源码 之 GUIChooser.java

myGUIChooser.java 可直接编译通过,效果如图(在相同目录下请准备一张名为zhou.gif的图片)。

    按此在新窗口浏览图片            

代码如下(有关weka的部分代码仅注释掉,没有删去,方便大家对照weka源码学习):


//import weka.core.Memory;
//import weka.core.Version;
//import weka.gui.explorer.Explorer;
//import weka.gui.experiment.Experimenter;
//import weka.gui.beans.KnowledgeFlow;
//import weka.gui.beans.KnowledgeFlowApp;

import java.awt.Panel;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;//maybe dont used here
import javax.swing.SwingConstants;
import javax.swing.BorderFactory;


/**
* The main class for the Weka myGUIChooser. Lets the user choose
* which GUI they want to run.
*
* @author Len Trigg (trigg@cs.waikato.ac.nz)
* @author Mark Hall (mhall@cs.waikato.ac.nz)
* @version $Revision: 1.14.2.12 $
*/
public class myGUIChooser extends JFrame implements ActionListener{

  /** Click to open the mySimpleCLI */
  protected Button m_SimpleBut = new Button("Simple CLI");

  /** Click to open the Explorer */
  protected Button m_ExplorerBut = new Button("Explorer");

  /** Click to open the Explorer */
  protected Button m_ExperimenterBut = new Button("Experimenter");

  /** Click to open the KnowledgeFlow */
  protected Button m_KnowledgeFlowBut = new Button("KnowledgeFlow");

  /** The mySimpleCLI */
// protected mySimpleCLI m_mySimpleCLI;
protected JFrame m_mySimpleCLI;
  /** The frame containing the explorer interface */
  protected JFrame m_ExplorerFrame;

  /** The frame containing the experiment interface */
  protected JFrame m_ExperimenterFrame;

  /** The frame containing the knowledge flow interface */
  protected JFrame m_KnowledgeFlowFrame;

  /** The weka image */
  Image m_weka = Toolkit.getDefaultToolkit().
    getImage(ClassLoader.getSystemResource("zhou.gif"));

  
  /**
   * Creates the experiment environment gui with no initial experiment
   */
  public myGUIChooser() {

    super("myWeka GUI Chooser");
    
    Image icon = Toolkit.getDefaultToolkit().
    getImage(ClassLoader.getSystemResource("zhou.gif"));
    setIconImage(icon);

    this.getContentPane().setLayout(new BorderLayout());
    JPanel wbuts = new JPanel();
    wbuts.setBorder(BorderFactory.createTitledBorder("myGUI"));
    wbuts.setLayout(new GridLayout(2, 2));
    wbuts.add(m_SimpleBut);
    wbuts.add(m_ExplorerBut);
    wbuts.add(m_ExperimenterBut);
    wbuts.add(m_KnowledgeFlowBut);
    this.getContentPane().add(wbuts, BorderLayout.SOUTH);
    
    JPanel wekaPan = new JPanel();
    wekaPan.setToolTipText("Mr Zhou,Not a native bird of New Zealand!");
    ImageIcon wii = new ImageIcon(m_weka);
    JLabel wekaLab = new JLabel(wii);
    wekaPan.add(wekaLab);
    this.getContentPane().add(wekaPan, BorderLayout.CENTER);
    
    JPanel titlePan = new JPanel();
    titlePan.setLayout(new GridLayout(8,1));
    titlePan.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
    titlePan.add(new JLabel("DMman Environment for",
                            SwingConstants.CENTER));
    titlePan.add(new JLabel("Knowledge Analysis",
                            SwingConstants.CENTER));
    titlePan.add(new JLabel(""));
    titlePan.add(new JLabel("Version 2007-4-10" ,
                            SwingConstants.CENTER));
    titlePan.add(new JLabel(""));
    titlePan.add(new JLabel("(c) 1999 - 2007",
    SwingConstants.CENTER));
    titlePan.add(new JLabel("University of Ocean",
    SwingConstants.CENTER));
    titlePan.add(new JLabel("Qing Dao",
    SwingConstants.CENTER));
    this.getContentPane().add(titlePan, BorderLayout.NORTH);

  m_SimpleBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        try {
            m_mySimpleCLI = new JFrame("m_mySimpleCLI");
   JOptionPane.showMessageDialog(m_ExperimenterFrame,"You pressed SimpleCLI.","info",JOptionPane.INFORMATION_MESSAGE);
          } catch (Exception ex) {
            throw new Error("Couldn't start m_ExperimenterFrame!");
          }
      }
    });


  m_ExplorerBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
       
           m_ExplorerFrame = new JFrame("m_ExplorerFrame");
           Object[] options = {"Yes, please",
                    "No, thanks",
                    "cancel"};
int n = JOptionPane.showOptionDialog(m_ExplorerFrame,
    "You pressed Explorer",  "A Silly Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
    null,  options, options[2]);
m_ExplorerFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent w) {
             System.out.println("m_ExplorerFrame window close--conment by DMman");
              m_ExplorerFrame.dispose();
              m_ExplorerFrame = null;
              m_ExplorerBut.setEnabled(true);
             // checkExit();
            }
          });
          
    }
   });

   m_ExperimenterBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      
          try {
            m_ExperimenterFrame = new JFrame("m_ExperimenterFrame");
   JOptionPane.showMessageDialog(m_ExperimenterFrame,"You pressed ExperimenterFrame.","info",JOptionPane.INFORMATION_MESSAGE);
          } catch (Exception ex) {
            throw new Error("Couldn't start m_ExperimenterFrame!");
          }
    }
     });

    
  }

  /** variable for the myGUIChooser class which would be set to null by the memory
      monitoring thread to free up some memory if we running out of memory
   */
  private static myGUIChooser m_chooser;

public void actionPerformed(ActionEvent e) {

    try {
      
    } catch (Exception ex) {
      System.err.println(ex.getMessage());
    }
  }

  public static void main(String [] args) {

//    LookAndFeel.setLookAndFeel();
    
    try {

      m_chooser = new myGUIChooser();
      m_chooser.setVisible(true);
  
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println(ex.getMessage());
    }
m_chooser.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent w) {
             System.out.println("window close--conment by DMman");
              m_chooser.dispose();
              m_chooser = null;
             
            }
          });
m_chooser.pack();
  }
}


--  作者:DMman
--  发布时间:4/12/2007 8:55:00 AM

--  
更多内容尽在http://blogger.org.cn/blog/blog.asp?subjectid=2725&name=DMman
欢迎大家提问交流,谢谢。
--  作者:jay2jin
--  发布时间:5/27/2007 10:33:00 PM

--  
顶一下先 .....  DMman  ~~~
--  作者:yinrenxingzhe
--  发布时间:3/7/2008 1:33:00 PM

--  
DMman,支持你!
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
81.055ms