package calculatefiles;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import calculatefiles.common.CenterWindow;
import calculatefiles.common.GBC;
public class OutWindows extends JDialog {
private JTextField aimfield, commontfield,
explainfield, whitefield,allfield;
private JButton btn;
private JLabel label;
private JTextArea text;
public OutWindows() {
inivite();
}
public void inivite(){
this.setLayout(new BorderLayout());
this.add(buildPanel());
this.add(label,"South");
this.setSize(400, 350);
this.setTitle("计算java 代码行工具");
this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
CenterWindow.centerWindow(this);
this.setVisible(true);
}
public void initialText(){
label = new JLabel();
aimfield = new JTextField(18);
aimfield.setEditable(false);
commontfield = new JTextField(10);
commontfield.setEditable(false);
explainfield = new JTextField(10);
explainfield.setEditable(false);
whitefield = new JTextField(10);
whitefield.setEditable(false);
allfield = new JTextField(10);
allfield.setEditable(false);
text = new JTextArea(3,4);
text.setLineWrap(true);
text.setText("此工具可以计算一些包含java的文件");
text.setEditable(false);
}
public JPanel buildPanel(){
initialText();
JPanel p = new JPanel();
p.setLayout(new GridBagLayout());
p.add(new JLabel("目标文件:"),new GBC(0,0).setInset(0,15,15,15).setFill(GBC.WEST));
p.add(aimfield,new GBC(1,0,2,1).setInset(0,15,15,15).setFill(GBC.WEST));
p.add(buildBtn(),new GBC(3,0).setInset(0,15,15,15).setFill(GBC.WEST));
p.add(new JLabel("代码行数:"),new GBC(0,1).setFill(GBC.WEST));
p.add(commontfield,new GBC(1,1).setInset(15).setFill(GBC.WEST));
p.add(new JLabel("注释行数:"),new GBC(0,2).setFill(GBC.WEST));
p.add(explainfield,new GBC(1,2).setInset(7).setFill(GBC.WEST));
p.add(text,new GBC(2,2,3,4).setFill(GBC.WEST).setInset(15));
p.add(new JLabel("空白行数:"),new GBC(0,3).setFill(GBC.WEST));
p.add(whitefield,new GBC(1,3).setInset(15).setFill(GBC.WEST));
p.add(new JLabel("总共行数:"),new GBC(0,4).setFill(GBC.WEST));
p.add(allfield,new GBC(1,4).setInset(15).setFill(GBC.WEST));
this.getRootPane().setDefaultButton(btn);
return p;
}
public JButton buildBtn(){
if(btn == null){
btn = new JButton("...");
}
btn.addActionListener(new OutAction(this));
return btn;
}
public static void main(String[] args){
new OutWindows();
}
public JTextField getCommontfield() {
return commontfield;
}
public JTextField getExplainfield() {
return explainfield;
}
public JTextField getWhitefield() {
return whitefield;
}
public JTextField getAllfield() {
return allfield;
}
public JTextField getAimfield() {
return aimfield;
}
public JLabel getLabel(){
return label;
}
}