Posted by: Java_help April 14, 2011
Java
Login in to Rate this Post:     0       ?        

Please help me with this..Thank you in advance :)



In this lab, you are required to program with Swing and File I/O.

 

Your application will be a Graphical User Interface (GUI) that looks similar to these:

<!--[if !vml]--><!--[endif]--> <!--[if !vml]--><!--[endif]-->

 

This GUI contains several components:

<!--[if !supportLists]-->·      <!--[endif]-->a JTextArea component, in which you can type text or display content of a file.

<!--[if !supportLists]-->·      <!--[endif]-->a JMenuBar component, which contains two JMenu components

<!--[if !supportLists]-->1)    <!--[endif]-->a JMenu component which is labeled "File". This menu contains three items: "Open", "Save As" and "Exit".

<!--[if !supportLists]-->2)    <!--[endif]-->a JMenu component which is labeled "Style". This menu contains two sub-menus: the JMenu "font-type" and the JMenu "textAreaColor". The "font-type" menu contains three items: "Plain", "Bold" and "Italic". The "textAreaColor" menu contains two sub-menus: the JMenu "Foreground-Color" and the JMenu "Background-Color", each contains four items representing the color: “Pink”, “White”, “Blue” and “Black”.

 

You are required to achieve the following tasks with these components:

<!--[if !supportLists]-->(1)  <!--[endif]-->If you click “File”-> “Open”, you should be able to open a file window as below. You can open a file by either double clicking the file name or typing in the file name and hitting the “open” button, just as you normally do. The content of the file you selected should be shown in the text area. Only the content of a plain text file is required to be shown correctly. If the file doesn’t exist (double clicking the file name won’t has this problem, but if you type into the file name, it is possible), show a message box to indicate such an error. If you click “Cancel”, this window will be closed and nothing happens.


<!--[if !vml]--><!--[endif]-->

 

 

 

 

 

 

HINT: Design of this “open” window is NOT your job; it’s already done in the JFileChoose class. Go to http://java.sun.com/j2se/1.4.2/docs/api/ to check what functions and fields this class provides. What you need to do is figuring out which file has been selected and how to read its context into the text area. As to the message box, refer to the JOptionPane class.

<!--[if !supportLists]-->(2)           <!--[endif]-->If you click “File”-> “Save As”, you should be able to open a file window as below. After you double click a file name or type in a file name and click “Save”, the text currently shown in the text area should be saved in that file. You are NOT required to handle a double confirmation if the file has existed, so be careful that you may override some useful files (just be careful by yourself, this lab doesn’t require you to do anything about it). If you click “Cancel”, this window will be closed and nothing happens.

<!--[if !vml]--><!--[endif]-->

 

 

 

 

 

 

 

 

HINT: Same as task (1), this window is also manipulated by the JFileChoose class.

<!--[if !supportLists]-->(3)           <!--[endif]-->If you click “File”-> “Exit”, your text editor window will be closed and the program stops.

<!--[if !supportLists]-->(4)           <!--[endif]-->You should be able to change the font style, the foreground color and the background color of the text area.

Read Full Discussion Thread for this article