sol6 - 1.124J Foundations of Software Engineering Problem...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1.124J Foundations of Software Engineering Problem Set 6 - Solution Due Date: Thursday 11/2/00 Problem 1:[60%] Part A: Sol6_1.java public class Sol6_1a { public static void main(String args[]) { new Plotter1(); } } plotter.java import java.io.*; import java.util.*; public class Plotter1 { Plotter1() { readData(); } void readData() {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
FileInputStream ifp; double x[], y[]; x = y = null; String fileName = new String("data6_1"); try{ ifp = new FileInputStream(fileName); } catch(FileNotFoundException e) { System.out.println(" File " + fileName + " was not found."); return; } int i, n=0; InputStreamReader rd = new InputStreamReader(ifp); StreamTokenizer tk = new StreamTokenizer(rd); try { tk.nextToken(); n = (int)tk.nval; x = new double[n]; y = new double[n]; for(i=0;i<n;i++) { tk.nextToken(); x[i] = (double)tk.nval; tk.nextToken(); y[i] = (double)tk.nval; } ifp.close(); } catch(IOException e) { System.out.println("IOException: " + e.getMessage()); } System.out.println("\n" + n + " points have been read"); for(i=0;i<n;i++) { System.out.print("x[" + (i+1) +"]=" + x[i]);
Background image of page 2
System.out.println("\ty[" + (i+1) +"]=" + x[i]); } } } Part B: Sol6_1.java public class Sol6_1 { public static void main(String args[]) { new Plotter(); } } plotter.java import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; public class Plotter extends JFrame implements ActionListener { private JMenuBar menuBar ; private JMenu fileMenu; private JMenuItem importMI, exitMI; private JToolBar toolBar = new JToolBar(); private JButton dashedButton, solidButton; private JPanel contentPane; private Plot plot;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
String fileName; FileInputStream ifp =null; public Plotter() { super("Problem Set 6 - Problem 3: Plotter"); JPopupMenu.setDefaultLightWeightPopupEnabled(false); setSize(500,500); setMenuBar(); contentPane = new JPanel() ; contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); setToolBar(); setPlot(); setContentPane(contentPane); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } } ); } private void setMenuBar() { menuBar = new JMenuBar(); fileMenu = new JMenu("File"); menuBar.add(fileMenu); importMI = new JMenuItem("Import Data"); importMI.addActionListener(this); fileMenu.add(importMI); exitMI = new JMenuItem("Exit"); exitMI.addActionListener(this); fileMenu.add(exitMI);
Background image of page 4
setJMenuBar(menuBar); } private void setToolBar() { toolBar = new JToolBar(); dashedButton = new JButton(new ImageIcon("dashed.gif")); dashedButton.setMnemonic(KeyEvent.VK_D); dashedButton.setToolTipText("Dashed line"); dashedButton.addActionListener(this);
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/04/2011 for the course ESD 1.124 taught by Professor Kevinamaratunga during the Fall '00 term at MIT.

Page1 / 15

sol6 - 1.124J Foundations of Software Engineering Problem...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online