import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.jrock.util.ClassGen;
public class ClassGenApplication {
public Component createComponents() {
String inStr = "public className;\n" +
"private String variable1;\n" +
"private Integer variable2;\n" +
"private Double variable3;";
final JTextArea text1 = new JTextArea(inStr,20,40);
final JTextArea text2 = new JTextArea("",20,50);
text1.setFont(new java.awt.Font("Arial",java.awt.Font.PLAIN,20));
text2.setFont(new java.awt.Font("Arial",java.awt.Font.PLAIN,12));
// Create a scrollable text area
JScrollPane sp1 = new JScrollPane(text1);
JScrollPane sp2 = new JScrollPane(text2);
JButton button = new JButton("Generate!");
button.setMnemonic(KeyEvent.VK_I);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
text2.setText(
ClassGen.getClassContent(text1.getText()));
}
});
JPanel pane = new JPanel();
pane.setBorder(BorderFactory.createEmptyBorder(
20, //top
20, //left
200, //bottom
200) //right
);
pane.setLayout(new GridLayout(0, 1));
pane.add(sp1);
pane.add(button);
pane.add(sp2);
return pane;
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) { }
//Create the top-level container and add contents to it.
JFrame frame = new JFrame("类生成工具");
ClassGenApplication app = new ClassGenApplication();
Component contents = app.createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);
//Finish setting up the frame, and show it.
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
}
|