1 / 11

Housekeeping

Housekeeping. Milestone 1 goes out today Many aspects involved, so get started early Includes a separate paper discussion to be delivered along with Capstone specifics The next 10 days Wed 9/4: Schach Ch.13; Homework 1 assigned Thurs 9/5: Lab 1 due; Lab 2 (MDI, GridBag )

bonner
Download Presentation

Housekeeping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Housekeeping • Milestone 1 goes out today • Many aspects involved, so get started early • Includes a separate paper discussion to be delivered along with Capstone specifics • The next 10 days • Wed 9/4: Schach Ch.13; Homework 1 assigned • Thurs 9/5: Lab 1 due; Lab 2 (MDI, GridBag) • Mon 9/9: Class Modeling, Noun Extraction • Wed 9/11: Class Modeling Case Study • Thurs 9/12: Lab 3 (Visual Paradigm) due end of class

  2. Adv. GUI Components (Deitel Chapter 25) Java Supports Multiple Document Interfaces (MDIs) with Parent and Child Windows: • JDesktopPane - Manages Child Windows • JInternalFrame - A Child Window • Displayed Within the Parent Window via JDesktopPane • JFrame - A Dynamically Created Independent Window • JFrames can be Moved Around Entire Screen • We will focus on JFrames

  3. *Multiple Document Interfaces(example)

  4. From Initially Running App (MDIGridBag.java): 220: public void actionPerformed(ActionEvent e){ … if (e.getActionCommand() == "Play Craps"){ playCrapsWindow(); } } 232: public void playCrapsWindow(){ MDICrapsmyCraps = newMDICraps(this); } Note: • Calling MDICraps(this) creates a new instance of Craps • Craps will Create (and Run in) its own JFrame • "this" provides MDICraps Constructor with Reference to object instance that Created the MDICraps instance

  5. MDICraps Instance Runs in Independent Window 52: public MDICraps(MDIGridBag creatorLink) {//MDICraps.java creator = creatorLink; JFrame frame =new JFrame("Craps Game"); Container c = frame.getContentPane(); ... 113: frame.setSize(400,200); frame.show(); // frame MUST show itself Note: • Craps Constructor Creates an new JFrame in which to Run • creatorLink is Reference to Caller (Creator) of MDICraps

  6. MDICraps Instance actionPerformed method 119: public void actionPerformed( ActionEvent e ){ … if(e.getSource()== sendToCreatorButton){ creator.AddToCrapsTotal(bankRoll); bankRoll = 0; bankRollText.setText (Integer.toString(bankRoll)); } } Note: • Via its constructor, Craps instance has a "creator" reference to the application that dynamically allocated the Craps instance. • Reference allows Craps instance to invoke methods of the creating application.

  7. Columns 0 1 2 0 Rows 1 2 3 4 *Focus: GridBagLayout GUI • GridBagLayout: most Flexible GUI Layout Manager • Allows GUI Components to Span Multiple Rows and Columns • Components can be added in any Order • First Step: Determine Desired Appearance of GUI • GridBagConstraints Specifies How each Component is Placed in the GUI

  8. In Application using a GridBagLayout GUI: public void init() { //similar to line 122 of MDIGridBag JFrame frame = new JFrame(“MDIGridBag”); container = frame.getContentPane(); gbLayout = new GridBagLayout(); container.setLayout( gbLayout ); // instantiate gridbag constraints gbConstraints = new GridBagConstraints(); • Note: A GridBagConstraints object Specifies how a Component is Placed in a GridBagLayout Container: • gridx, gridy: Column,Row in which Component will be placed • gridwidth, gridheight: #columns, rows Component Occupies • weightx,weighty: extra space allocated horizontally, vertically

  9. Using GridBag Constraints (note: not code from sample) JTextArea textArea = new JTextArea("Initial text"); // define GUI component constraints gbConstraints.gridx = 0; //column gbConstraints.gridy = 5; // row gbConstraints.gridheight = 2;// spans 2 rows gbConstraints.weightx = 0; //no horiz growth on own gbConstraints.weighty = 1; // rel wt of vert growth gbConstraints.fill=GridBagConstraints.BOTH; //if area too big gbConstraints.gridwidth=GridBagConstraints.REMAINDER; addComponent( new JScrollPane(textArea) ); //scroll bars ... private void addComponent( Component c ) { gbLayout.setConstraints( c, gbConstraints ); container.add( c ); } // add component

  10. Aside: Reading From Files 245: private String getDataFromFile(){ //MDIGridBag String readInText = null; try { //assoc file with file handle infile = new FileInputStream("data.dat"); // assoc file handle with I/O stream BufferedReader dataFile = new BufferedReader(new InputStreamReader(infile)); readInText = dataFile.readLine(); dataFile.close(); } catch (FileNotFoundException e){ System.out.println("File Not Found" + infile); } catch (IOException e){ System.out.println("IOException"); } return readInText; }

  11. ICE:Comm Between GUI Content Panes • Alter the source code as necessary so that the MDIGridBag instance has a button that causes the current “Sum of Craps Totals…” value to be sent to a particular instance of MDICraps.

More Related