帮忙改程序!!!在线等待,急用!!!
这是我的程序,运行没有问题,但是本人脑子里没有OO的概念,所以只写了2个class,从设计上说是太失败了:(
那位大侠能够按照OO的标准帮我改一下,把程序多分出几个class,比如save, load和add.(因为还需要写测试程序和UML,尤其是UML,要使这个结构,就死掉了:()多谢多谢了!!JDK1.3
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
public class GymLogProgram implements ActionListener {
//declare public variables
JFrame frame;
JTextArea editor; //a textarea to display a log ,and is editable
JTextField day;
JTextField repititions;
JTextField sets;
JTextField program;
JTextField intensity;
JComboBox jc; //all kinds of exercise
String strExercise = new String ("Legs");
boolean isfirst = true;
Font editorfont = new Font("Monospaced",Font.PLAIN,12);
int tabsize = 5;
/**the main function
*/
public static void main(String[] args){
GymLogProgram gymlogprogram = new GymLogProgram();
gymlogprogram.init();
}
public void init(){
//initialise the frame
frame = new JFrame("GymLogProgram");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//button controls
/* for Load and Save button*/
JPanel controlpanel = new JPanel();
JButton openbutton = new JButton("Load Log");
JButton writebutton = new JButton("Save Log");
JButton exitbutton = new JButton("Exit");
exitbutton.addActionListener(this);
openbutton.addActionListener(this);
writebutton.addActionListener(this);
controlpanel.add(writebutton);
controlpanel.add(openbutton);
controlpanel.add(exitbutton);
frame.getContentPane().add(controlpanel,"North");
//set the part for inserting information into a log
//set the layout
JPanel insertpanel = new JPanel();
JPanel insertpanel1 = new JPanel();
JPanel insertpanel2 = new JPanel();
//Jpanel insertpanel3 = new Jpanel();
insertpanel.add(insertpanel1, "North");
//insertpanel.add(insertpanel2, "Center");
insertpanel.add(insertpanel2, "South");
insertpanel1.setLayout( new GridLayout(3,6));
//set the section to insert the number of days of a log
JLabel daylabel = new JLabel("Day");
insertpanel1.add(daylabel);
day = new JTextField("",1);
insertpanel1.add(day);
//set the section to insert a exercise type
JLabel exerciselabel = new JLabel("Exercise");
insertpanel1.add(exerciselabel);
jc = new JComboBox();
jc.addItem("Legs");
jc.addItem("Biceps Superset");
jc.addItem("Triceps Superset");
jc.addItem("Stomach");
jc.addItem("Chest & Back");
jc.addItem("Shoulders Triset");
jc.addItem("Arms");
/** Provides actions to the list of exercises.
*/
jc.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(ItemEvent ie) {
strExercise = (String)ie.getItem();
}
});
insertpanel1.add(jc);
//set the section to insert the name of exercise
JLabel programlable = new JLabel("Program");
insertpanel1.add(programlable);
program = new JTextField("",1);
insertpanel1.add(program);
//set the section to insert the numbers of repititions
JLabel repititionslabel = new JLabel("Repititions");
insertpanel1.add(repititionslabel);
repititions = new JTextField("",1);
insertpanel1.add(repititions);
//set the section to insert the numbers of sets
JLabel setslabel = new JLabel("Sets");
insertpanel1.add(setslabel);
sets = new JTextField("",1);
insertpanel1.add(sets);
//set the section to insert the intensity of exercise
JLabel intensitylabel = new JLabel("Intensity");
insertpanel1.add(intensitylabel);
intensity = new JTextField("",1);
insertpanel1.add(intensity);
//set the ADD button
JButton ADD = new JButton("Add");
insertpanel2.add(ADD);
ADD.addActionListener(this);
frame.getContentPane().add(insertpanel,"South");
//editor
editor = new JTextArea(new PlainDocument(),"",20,60); //initializes a JTextArea with width 60 and height 20
editor.setFont(editorfont);
editor.setTabSize(tabsize);
JScrollPane scrollpane = new JScrollPane(editor);
frame.getContentPane().add(scrollpane,"Center");
frame.pack();
frame.show();
//centre the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
/////////////////////////////
/*create a user login window
*/
LoginDialog loginDlg = new LoginDialog( frame );
Dimension dlgSize = loginDlg.getSize();
if (dlgSize.height > screenSize.height) {
dlgSize.height = screenSize.height;
}
if (dlgSize.width > screenSize.width) {
dlgSize.width = screenSize.width;
}
loginDlg.setLocation((screenSize.width - dlgSize.width) / 2, (screenSize.height - dlgSize.height) / 2);
loginDlg.setVisible(true);
}
/////////////////
/** Brings up as file save dialog and save the file into a directry selected by the user.
*/
public File getAFileForSave(){
File file = null;
File currentdirectory = new File(".");
JFileChooser filechooser = new JFileChooser(currentdirectory);
int replycode = filechooser.showSaveDialog(frame);
if (replycode == JFileChooser.APPROVE_OPTION){
file = filechooser.getSelectedFile();
}
return file;
}
/** Brings up as imple file open dialog and returns the file selected by the user.
*/
public File getAFileToOpen(){
File file = null;
File currentdirectory = new File(".");
JFileChooser filechooser = new JFileChooser(currentdirectory);
int replycode = filechooser.showOpenDialog(frame);
if (replycode == JFileChooser.APPROVE_OPTION){
file = filechooser.getSelectedFile();
}