Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java thread: I have a question about Swing


Message #1 by "Brian Walker" <BRIANPWALKER@p...> on Sat, 6 Jan 2001 07:56:48 -0000
I have started something basic.With the code below it compiles and runs.It
has a text field, a horizontal and vertical scroll bar and a basic pull
down menu.On the menu is open, new, save, saveas.. etc...My question is,
how would I go about writing the code for the save or saveas.. item on the
pull down menu , that would actually save my text to a Floppy disk.:)Also
where would I start to look for this kind of information and what is it
called?Any recommended books? Thank You
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class MyMenu3 extends JFrame {
	
	JTextArea textArea;
	JScrollPane scrollPane;

	public MyMenu3 () {
	
	JMenuBar menuBar;
	JMenu menu;
	JMenuItem menuItem;

	addWindowListener(new WindowAdapter()
         {  public void windowClosing(WindowEvent e)
            {  System.exit(0);
            }
         } );

//Add Components
	
	Container contentPane = getContentPane();
	JPanel panel = new JPanel();
	textArea = new JTextArea(300, 300);
	scrollPane = new JScrollPane(textArea,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
	contentPane.add(panel, "East");
	contentPane.add(scrollPane);
        
//Create Menu Bar

	menuBar = new JMenuBar();
	setJMenuBar(menuBar);

//Build Menu

	menu = new JMenu("File");
	menuBar.add(menu);

//Make menu Item

	menuItem = new JMenuItem("Save");
	menu.add(menuItem);
	}
	

public static void main(String[] args) {
	MyMenu3 window = new MyMenu3 ();
	window.setSize(300, 300);
	window.setVisible(true);
	}
     
}

---
You are currently subscribed to pro_java as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-pro_java-$subst('Recip.MemberIDChar')@p2p.wrox.com

  Return to Index