/**
*
*/
package StringAlign;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Dimension;
import java.awt.TextArea;
import java.awt.Rectangle;
import java.awt.Button;
import java.awt.TextField;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.awt.Label;
import java.awt.Font;
/**
* @author Owner
*
*/
public class align extends Frame {
String fname=""; // @jve:decl-index=0:
account ac=new account(); // @jve:decl-index=0:
private static final long serialVersionUID = 1L;
private TextArea textArea = null;
private Button button = null;
private TextField textField = null;
private Button button1 = null;
private Button button2 = null;
private Button button3 = null;
private Button button4 = null;
private Label label = null;
/**
* This is the default constructor
*/
public align() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
label = new Label();
label.setBounds(new Rectangle(48, 34, 279, 23));
label.setAlignment(Label.CENTER);
label.setFont(new Font("Dialog", Font.BOLD, 14));
label.setText("欢迎使用文本对齐工具");
this.setLayout(null);
this.setSize(394, 423);
this.setTitle("文本对齐工具");
this.add(getTextArea(), null);
this.add(getButton(), null);
this.add(getTextField(), null);
this.add(getButton1(), null);
this.add(getButton2(), null);
this.add(getButton3(), null);
this.add(getButton4(), null);
this.add(label, null);
this.setVisible(true);
}
/**
* This method initializes textArea
*
* @return java.awt.TextArea
*/
private TextArea getTextArea() {
if (textArea == null) {
textArea = new TextArea();
textArea.setBounds(new Rectangle(31, 60, 329, 209));
}
return textArea;
}
/**
* This method initializes button
*
* @return java.awt.Button
*/
private Button getButton() {
if (button == null) {
button = new Button();
button.setBounds(new Rectangle(25, 295, 92, 27));
button.setLabel("打开文件");
button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String input="",str="";
Frame f=new Frame("Test FileDialog");
FileDialog d=new FileDialog(f,"My FileDialog");
d.setVisible(true);
fname=d.getDirectory()+d.getFile();
if(fname.equals("nullnull"))
textField.setText("");
else
textField.setText(fname);
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(fname));
} catch (FileNotFoundException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
try {
while((input=in.readLine())!=null)
{
str+=input+"\r\n";
}
in.close();
} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
textArea.setText(str);
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return button;
}
/**
* This method initializes textField
*
* @return java.awt.TextField
*/
private TextField getTextField() {
if (textField == null) {
textField = new TextField();
textField.setBounds(new Rectangle(142, 295, 225, 29));
}
return textField;
}
/**
* This method initializes button1
*
* @return java.awt.Button
*/
private Button getButton1() {
if (button1 == null) {
button1 = new Button();
button1.setBounds(new Rectangle(40, 342, 78, 23));
button1.setLabel("居中");
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String input="",str="",str1="";
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(fname));
} catch (FileNotFoundException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
try {
account formatter = new account(20, account.JUST_CENTER);
while((input=in.readLine())!=null)
{
if((input.indexOf("\r\n"))==0)
{
input.replace("\r\n",null);
str+=formatter.format(input);
}
str1=input.trim();
str+=formatter.format(str1)+"\r\n";
}
in.close();
} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
textArea.setText(str);
try {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fname)));
if (out != null)
out.write(str);
out.close();
}
catch (IOException e1)
{
// TODO 自动生成 catch 块
e1.printStackTrace();
}
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return button1;
}
/**
* This method initializes button2
*
* @return java.awt.Button
*/
private Button getButton2() {
if (button2 == null) {
button2 = new Button();
button2.setBounds(new Rectangle(158, 342, 78, 23));
button2.setLabel("左对齐");
button2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String input="",str="",str1="";
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(fname));
} catch (FileNotFoundException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
try {
account formatter = new account(20, account.JUST_LEFT);
while((input=in.readLine())!=null)
{
if((input.indexOf("\r\n"))==0)
{
input.replace("\r\n",null);
str+=formatter.format(input);
}
str1=input.trim();
str+=formatter.format(str1)+"\r\n";
}
in.close();
} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
textArea.setText(str);
try {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fname)));
if (out != null)
out.write(str);
out.close();
}
catch (IOException e1)
{
// TODO 自动生成 catch 块
e1.printStackTrace();
}
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
}
});
}
return button2;
}
/**
* This method initializes button3
*
* @return java.awt.Button
*/
private Button getButton3() {
if (button3 == null) {
button3 = new Button();
button3.setBounds(new Rectangle(276, 342, 78, 23));
button3.setLabel("右对齐");
button3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String input="",str="",str1="";
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(fname));
} catch (FileNotFoundException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
try {
account formatter = new account(20, account.JUST_RIGHT);
while((input=in.readLine())!=null)
{
if((input.indexOf("\r\n"))==0)
{
input.replace("\r\n",null);
str+=formatter.format(input);
}
str1=input.trim();
str+=formatter.format(str1)+"\r\n";
}
in.close();
} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
textArea.setText(str);
try {
PrintWriter o