1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
package com.labosun.articlewriter.form;
import java.awt.*;
import javax.swing.*;
import com.labosun.articlewriter.bo.*;
import com.labosun.articlewriter.listeners.ValidateFieldAction;
/**
* This class is used to create, open, save (etc...) the articles
* @author Anthony
*
*/
public class Writer extends JFrame{
/**
* List of variables used to write the article
*/
public JPanel leftContent = null;
public JPanel rigthContent = null;
public Dimension windowSize;
public Dimension componentSize;
public String state = "article_title";
public JLabel fieldType = null;
public JTextField titleField = null;
public JTextArea contentField = null;
public JButton validFieldButton = null;
/**
* This is the default constructor for the class Writer
*
*/
public Writer() {
super();
initialize();
}
/**
* This method is used to define initials parameters of the window
*
*/
public void initialize() {
this.setSize(1000, 800);
this.windowSize = this.getSize();
this.setLocationRelativeTo(null);
this.setTitle("Sun Laboratory's Article Writer");
this.setContentPane(getJContentPane());
setLayout(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* this method permit to define content's components
* @return
*/
public JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.add(getFieldType());
componentSize = getFieldType().getPreferredSize();
getFieldType().setBounds(windowSize.width/2-componentSize.width/2, 90, componentSize.width, componentSize.height);
jContentPane.add(getTitleField());
componentSize = getTitleField().getPreferredSize();
componentSize.width = 400;
getTitleField().setBounds(windowSize.width/2-componentSize.width/2, 110, componentSize.width, getTitleField().getPreferredSize().height);
jContentPane.add(getValidFieldButton());
componentSize = getValidFieldButton().getPreferredSize();
getValidFieldButton().setBounds(windowSize.width/2-componentSize.width/2, 135, componentSize.width, getTitleField().getPreferredSize().height);
}
return jContentPane;
}
/**
* This method is the getter of the fieldType label
* @return
*/
public JLabel getFieldType() {
if (fieldType == null) {
fieldType = new JLabel();
if (state == "article_title") {
fieldType.setText("Enter the article's title : ");
}
}
return fieldType;
}
/**
* This is the getter of the JTextField
* @return
*/
public JTextField getTitleField() {
if (titleField == null) {
titleField = new JTextField();
}
return titleField;
}
/**
* This is the getter for the validating button
* @return
*/
public JButton getValidFieldButton() {
if (validFieldButton == null) {
validFieldButton = new JButton();
validFieldButton.setText("Validate informations");
validFieldButton.addActionListener(new ValidateFieldAction(this));
}
return validFieldButton;
}
public static void main(String[] args) {
new Index();
}
} |
Partager