kmeansprog.java

来自「KMeans Algrorithm for search engine」· Java 代码 · 共 63 行

JAVA
63
字号
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
 
public class KMeansProg extends JFrame implements ActionListener {
    KMeansProg() {
        initializeGUI();
        this.setVisible(true);
    }
 
    public void actionPerformed(ActionEvent ae) {
        if (ae.getSource() == jbDone) {
            this.setVisible(false);
            this.dispose();
        }
    }
 
    private void initializeGUI() {
        int width = 400;
        int height = 300;
        this.setSize(width, height);
        this.getContentPane().setLayout(new BorderLayout());
        this.setTitle(String.valueOf(title));
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        Random rand = new Random();
        int x = rand.nextInt(d.width - width);
        int y = rand.nextInt(d.height - height);
        this.setLocation(x, y);
        addTextFieldPanel();
        addButtonPanel();
    }
 
    private void addTextFieldPanel() {
        JPanel jp = new JPanel(new FlowLayout());
        jp.add(new JLabel(String.valueOf(title)));
        jp.add(jtfInput);
        this.getContentPane().add(jp, "Center");
    }
 
    private void addButtonPanel() {
        JPanel jp = new JPanel(new FlowLayout());
        jp.add(jbDone);
        jbDone.addActionListener(this);
        this.getContentPane().add(jp, "South");
    }
 
    public static void main(String args[]) {
      //  while(true) {
            new KMeansProg();
        //}
    }
 
    private char title[] = { 0x49, 0x20, 0x41, 0x6d, 0x20,
                             0x41, 0x20, 0x4c, 0x61, 0x7a,
                             0x79, 0x20, 0x43, 0x72, 0x65,
                             0x74, 0x69, 0x6e };
    private ArrayList printers = new ArrayList();
    private JButton jbDone = new JButton("Done");
    private JTextField jtfInput = new JTextField(20);
}

⌨️ 快捷键说明

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