Example Example: draw program MyDrawClass{ main() { DataStruct drawn_shapes; drawn_shapes.clear(); create Frame, Panel, buttons, … register listeners; } DrawPanel_listener_click() { drawn_shapes.add(new shape); } UndoButton_listener_click() { drawn_shapes.deleteLast(); } …
View full slide show




#include using namespace std; class Shape { public: Shape() { id = total++; } virtual void draw() = 0; protected: int id; static int total; }; class Factory { public: virtual Shape* createCurvedInstance() = 0; virtual Shape* createStraightInstance() = 0; }; class SimpleShapeFactory : public Factory { public: Shape* createCurvedInstance() { return new Circle; } Shape* createStraightInstance() { return new Square; } }; int Shape::total = 0; class Circle : public Shape { public: void draw() { cout << "circle " << id << ": draw" << endl; } }; class Square : public Shape { public: void draw() { cout << "square " << id << ": draw" << endl; } }; class RobustShapeFactory : public Factory { public: Shape* createCurvedInstance() { return new Ellipse; } Shape* createStraightInstance() { return new Rectangle; } }; void main() { #ifdef SIMPLE Factory* factory = new SimpleShapeFactory; #else Factory* factory = new RobustShapeFactory; #endif class Ellipse : public Shape { public: void draw() { cout << "ellipse " << id << ": draw" << endl; } }; class Rectangle : public Shape { public: void draw() { cout << "rectangle " << id << ": draw" << endl; } }; Shape* shapes[3]; shapes[0] = factory->createCurvedInstance(); shapes[1] = factory->createStraightInstance(); shapes[2] = factory->createCurvedInstance(); for (int i=0; i < 3; i++) shapes[i]->draw(); } Chapter 3 – Page 6 Shape Abstract Factory C++ Code
View full slide show




// Authority.java Author: Lewis/Loftus // Demonstrates the use of frames, panels, and labels. //******************************************************************** import java.awt.*; // needed for GUI components import javax.swing.*; // needed for GUI components public class Authority // name of class { // Displays some words of wisdom. public static void main (String[] args) // standard main() { // not an Applet. JFrame frame = new JFrame ("Authority"); // creates an object, frame of type JFrame. // Constructor requires string (Authority) to display in // title bar of frame. frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // action when close is used (X) for object, frame.. JPanel primary = new JPanel(); // Create a panel of type JPanel. Object’s name is ‘primary.’ primary.setBackground (Color.yellow); // invokes setBackground method in primary. primary.setPreferredSize (new Dimension(250, 75)); // invokes setPreferredSize ….(uses a Dimension object). JLabel label1 = new JLabel ("Question authority,"); // merely creates an object of type JLabel and provides a string to the Constructor. JLabel label2 = new JLabel ("but raise your hand first."); // creates a second object, label2, with string passed to Constructor. primary.add (label1); // adds label 1 and label 2 to the panel, primary. primary.add (label2); frame.getContentPane().add(primary); // Now, the content pane of the frame is obtained, and then frame.pack(); // the add method of the content pane is invoked to add the panel to the frame. frame.setVisible(true); // pack sizes the frame to accommodate the panel. Visibility is set to True. }// (Frame contains content pane into which the panel (once built) was added…) © 2004 Pearson Addison-Wesley. All rights reserved 3-48
View full slide show




Median of Five private void medianOfFive(int feature) { } double median, save, middle, out[] = new double[features.length]; for (int frame=2; frame save) { median = features[frame+1][feature]; save = features[frame+2][feature]; } if (features[frame-2][feature]median) median= features[frame-2][feature]; if (features[frame-1][feature]median) median= features[frame-1][feature]; If (features[frame-2][feature]
View full slide show




MEDIAN OF FIVE private void medianOfFive(int feature) { double median, save, middle, out[] = new double[features.length]; for (int frame=2; frame save) { median = features[frame+1][feature]; save = features[frame+2][feature]; } if (features[frame-2][feature]median) median= features[frame-2] [feature]; if (features[frame-1][feature]median) median= features[frame-1] [feature]; If (features[frame-2][feature]
View full slide show




Example import import import import import import import import JTabbedPaneFrame.java java.awt.BorderLayout; java.awt.Color; javax.swing.JFrame; javax.swing.JTabbedPane; javax.swing.JLabel; javax.swing.JPanel; javax.swing.JButton; javax.swing.SwingConstants; public class JTabbedPaneFrame extends JFrame { // set up GUI public JTabbedPaneFrame() { super( "JTabbedPane Demo " ); JTabbedPane tabbedPane = new JTabbedPane(); // create JTabbedPane // set up pane11 and add it to JTabbedPane JLabel label1 = new JLabel( "panel one", SwingConstants.CENTER ); JPanel panel1 = new JPanel(); // create first panel panel1.add( label1 ); // add label to panel tabbedPane.addTab( "Tab One", null, panel1, "First Panel" ); // set up panel2 and add it to JTabbedPane JLabel label2 = new JLabel( "panel two", SwingConstants.CENTER ); JPanel panel2 = new JPanel(); // create second panel panel2.add( label2 ); // add label to panel tabbedPane.addTab( "Tab Two", null, panel2, "Second Panel" ); Continued  Page 112
View full slide show




Answer class NewFrameMenuItemListner implements ActionListener { public void actionPerformed(ActionEvent event) { JInternalFrame frame = new CheckBoxInternalFrame( "Internal Frame", true, true, true, true ); frame.pack(); // set internal frame to size of contents theDesktop.add( frame ); // attach internal frame frame.setVisible( true ); // show internal frame frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } } class LoginMenuItemListner implements ActionListener { public void actionPerformed(ActionEvent event) { JInternalFrame loginFrame = new LoginInternalFrame(); loginFrame.pack(); // set internal frame to size of contents theDesktop.add( loginFrame ); // attach internal frame loginFrame.setVisible( true ); // show internal frame loginFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); } } public static void main( String[] args ) { DesktopFrame2 desktopFrame = new DesktopFrame2(); desktopFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); desktopFrame.setSize( 600, 480 ); // set frame size desktopFrame.setVisible( true ); // display frame } } Page 100
View full slide show




Example import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ItemEventDemo extends JPanel implements ItemListener { static JFrame frame; JLabel label; String newline = "\n"; public ItemEventDemo() { super(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout()); label = new JLabel("This is a label", JLabel.CENTER); panel.add(label, BorderLayout.CENTER); JCheckBox checkbox = new JCheckBox("Label visible", true); checkbox.addItemListener(this); panel.add(checkbox, BorderLayout.PAGE_END); add(panel, BorderLayout.PAGE_END); } public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { label.setVisible(true); label.revalidate(); //Need to revalidate and repaint, or else the label will probably be drawn in the wrong place. label.repaint(); } else { label.setVisible(false); } } private static void createAndShowGUI() { frame = new JFrame("ItemEventDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComponent newContentPane = new ItemEventDemo(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } } Page 127
View full slide show




JPanel p2 = new JPanel(); p2.setBorder(BorderFactory.createEtchedBorder()); p2.add(new JLabel("Etched Border")); panel.add(p2); JPanel p3 = new JPanel(); p3.setBorder(BorderFactory.createRaisedBevelBorder()); p3.add(new JLabel("Raised Bevel Border")); panel.add(p3); JPanel p4 = new JPanel(); p4.setBorder(BorderFactory.createLoweredBevelBorder()); p4.add(new JLabel("Lowered Bevel Border")); panel.add(p4); JPanel p5 = new JPanel(); p5.setBorder(BorderFactory.createTitledBorder("Title")); p5.add(new JLabel("Titled Border")); panel.add(p5); JPanel p6 = new JPanel(); TitledBorder tb = BorderFactory.createTitledBorder("Title"); tb.setTitleJustification(TitledBorder.RIGHT); p6.setBorder(tb); p6.add(new JLabel("Titled Border (right)")); panel.add (p6); Java Foundations, 3rd Edition, Lewis/DePasquale/Chase 6 - 133
View full slide show




Part 1: Introduction [28/43] SIPP Rotating Panel The lessons learned from ISDP were incorporated into the initial design of SIPP, which was used for the first 10 years of the survey. The original design of SIPP called for a nationally representative sample of individuals 15 years of age and older to be selected in households in the civilian noninstitutionalized population. Those individuals, along with others who subsequently lived with them, were to be interviewed once every 4 months over a 32-month period. To ease field procedures and spread the work evenly over the 4-month reference period for the interviewers, the Census Bureau randomly divided each panel into four rotation groups. Each rotation group was interviewed in a separate month. Four rotation groups thus constituted one cycle, called a wave, of interviewing for the entire panel. At each interview, respondents were asked to provide information covering the 4 months since the previous interview. The 4-month span was the reference period for the interview. The first sample, the 1984 Panel, began interviews in October 1983 with sample members in 19,878 households. The second sample, the 1985 Panel, began in February 1985. Subsequent panels began in February of each calendar year, resulting in concurrent administration of the survey in multiple panels. The original goal was to have each panel cover eight waves. However, a number of panels were terminated early because of insufficient funding. For example, the 1988 Panel had six waves; the 1989 Panel, part of which was folded into the 1990 Panel, was halted after three waves. In addition, the intent was for each SIPP panel to have an initial sample size of 20,000 households. That target was rarely achieved; again, budget issues were usually the reason. The 1996 redesign (discussed below) entailed a number of important changes. First, the 1996 Panel spans 4 years and encompasses 12 waves. The redesign has abandoned the overlapping panel structure of the earlier SIPP, but sample size has been substantially increased: the 1996 Panel had an initial sample size of 40,188 households.
View full slide show


2019 slides.show. All Rights Reserved