You will get email Reply within few hours

Friday 22 November 2013

2 small java assignments


Assignment 1 due: Small JAVA debugging exercise (Understanding Error Messages )needed before 11:55am Nov. 24, 2013 (CST).

Assignment 2 due: Small JAVA interactive program (Creating an Assignment Data File)needed before 11:55am Nov. 31, 2013 (CST).

Begin of Assignment 1

Understanding Error Messages
Using TextPad, open the file named Connections from the Chapter07 folder of the Data Disk that accompanies this book (see below for complete source). Use the Replace command on the Search menu to replace all occurrences of the word, Connections, with the word, Modems. Save the file as a Java source code file with the file name Modems. Then, compile the program.When TextPad displays errors in the Command Results window, double-click the first line of the first error message to return to that line in the TextPad coding window. Fix the error. Insert a comment line in your code identifying what caused the error. Compile again and repeat the process until the program is error free. Submit your source code to your instructor.

--- begin import of Connections.java ---

/*
            Chapter 7:        Connections
            Programmer:
            Date:
            Filename:         Connections.java
            Purpose:           This program creates a Swing interface Modem Connections
*/

importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjavax.swing.text.*;

public class Connections extendsJFrameimplementsActionListener
{
            //construct components
            JComboBoxfirstCombo = new JComboBox();
            JComboBoxsecondCombo = new JComboBox();
            JTextPanetextPane = new JTextPane();

            //construct instance of Connections
            public Connections()
            {
            }

            //create the menu system
            publicJMenuBarcreateMenuBar()
            {
                        //create an instance of the menu
                        setJMenuBar(mnuBar);

                        //construct and populate the File menu
                        JMenumnuFile =new JMenu("File", true);
                                    mnuFile.setDisplayedMnemonicIndex(0);
                                    mnuBar.add(mnuFile);

                                    JMenuItemmnuFileExit = new JMenuItem("Exit");
                                                mnuFileExit.setDisplayedMnemonicIndex(1);
                                                mnuFile.add(mnuFileExit);
                                                mnuFileExit.setActionCommand("Exit");
                                                mnuFileExit.addActionListener(this);

                        //construct and populate the Edit menu
                        JMenumnuEdit = new JMenu("Edit", true);
                                    mnuEdit.setDisplayedMnemonicIndex(0);
                                    mnuBar.add(mnuEdit);

                                    JMenuItemmnuEditInsert = new JMenuItem("Insert New Connections");
                                                mnuEditInsert.setDisplayedMnemonicIndex(0);
                                                mnuEdit.add(mnuEditInsert);
                                                mnuEditInsert.setActionCommand("Insert");
                                                mnuEditInsert.addActionListener(this);

                                    JMenumnuEditSearch = new JMenu("Search");
                                                            mnuEditSearch.setDisplayedMnemonicIndex(3);
                                                            mnuEdit.add(mnuEditSearch);

                                                JMenuItemmnuEditSearchByConnection = new JMenuItem("by Connection");
                                                            mnuEditSearchByConnection.setDisplayedMnemonicIndex(3);
                                                            mnuEditSearch.add(mnuEditSearchByConnection);
                                                            mnuEditSearchByConnection.setActionCommand("title");
                                                            mnuEditSearchByConnection.addActionListener(this);

                                                JMenuItemmnuEditSearchBySpeed = new JMenuItem("by Speed");
                                                            mnuEditSearchBySpeed.setDisplayedMnemonicIndex(3);
                                                            mnuEditSearch.add(mnuEditSearchBySpeed);
                                                            mnuEditSearchBySpeed.setActionCommand("studio");
                                                            mnuEditSearchBySpeed.addActionListener(this);

                                                JMenuItemmnuEditSearchByProtocol = new JMenuItem("by Protocol");
                                                            mnuEditSearchByProtocol.setDisplayedMnemonicIndex(3);
                                                            mnuEditSearch.add(mnuEditSearchByProtocol);
                                                            mnuEditSearchByProtocol.setActionCommand("year");
                                                            mnuEditSearchByProtocol.addActionListener(this);

                        returnmnuBar;
            }

            //create the content pane
            public Container createContentPane()
            {
                        //populate the JComboBox
                        fieldCombo.addItem("Dial-Up");
                        fieldCombo.addItem("DSL");
                        fieldCombo.addItem("Cable");
                                                fieldCombo.addItem("Satellite");

                        fieldCombo.addActionListener(this);
                        fieldCombo.setToolTip("Click the drop down arrow to display connection types.");

                        //populate the JComboBox
                        secondCombo.addItem("57600");
                        secondCombo.addItem("2304000");
                        secondCombo.addItem("460800");
                                                secondCombo.addItem("921600");

                        secondCombo.addActionListener(this);
                        secondCombo.setEditable(true);

                        //construct and populate the north panel
                        JPanelnorthPanel = new JPanel();
                                    northPanel.setLayout(new FlowLayout());
                                    //northPanel.add(sortPrompt);
                                    northPanel.add(fieldCombo);
                                    northPanel.add(secondCombo);

                        //create the JTextPane and center panel
                        JPanelcenterPanel = new JPanel();
                                    setTabsAndStyles(textPane);
                                    JTextPaneinternalTextPane = addTextToTextPane();
                                    JScrollPanepaneScrollPane = new JScrollPane(internalTextPane);
                                                paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                                                paneScrollPane.setPreferredSize(new Dimension(500, 200));
                                    centerPanel.add(paneScrollPane);

                        //create Container and set attributes
                        Container c = getContentPane();
                                    c.setLayout(new BorderLayout(10,10));
                                    c.add(northPanel,BorderLayout.NORTH);
                                    c.add(centerPanel,BorderLayout.CENTER);

                        return c;
            }

            //method to create tab stops and set font styles
            protected void setTabsAndStyles(JTextPanetextPane)
            {
                        //create Tab Stops
                        TabStop[] tabs = new TabStop[2];
                                    tabs[0] = new TabStop(200, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
                                    tabs[1] = new TabStop(350, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
                        TabSettabset = new TabSet(tabs);

                        //set Tab Style
                        StyleContexttabStyle = StyleContext.getDefaultStyleContext();
                        AttributeSetaset =
                                                tabStyle.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
                        textPane.setParagraphAttributes(aset, false);

                        //set Font Style
                        Style fontStyle =
                                                StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

                        Style regular = textPane.addStyle("regular", fontStyle);
                        StyleConstants.setFontFamily(fontStyle, "SansSerif");

                        Style s = textPane.addStyle("italic", regular);
                        StyleConstants.setItalic(s, true);

                        s = textPane.addStyle("bold", regular);
                        StyleConstants.setBold(s, true);

                        s = textPane.addStyle("large", regular);
                        StyleConstants.setFontSize(s, 16);
            }

            //method to add new text to the JTextPane
            public JTextPaneaddTextToTextPane()
            {
                        Document doc = textPane.getDocument();
                        try
                        {
                                    //clear previous text
                                    doc.remove(0,doc.getLength());

                                    //insert title
                                    doc.insertText(0,"\nCONNECTIONS\tNUMBERS\t PROTOCOLS\n", textPane.getStyle("regular"));

  }
                        catch (BadLocationExceptionble)
                        {
                                    System.err.println("Couldn't insert text.");
                        }

                        returntextPane;
            }

            //event to process user clicks
            public void actionPerformed(ActionEvent e)
            {

}
            //main method executes at run time
            public static void main(String args[])
            {
                        JFrame.setDefaultLookAndFeelDecorated(true);
            Connections f = new Connections();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
                        f.setJMenuBar(f.createMenuBar());
                        f.setContentPane(f.createContentPane());
            f.setSize(600,375);
            f.setVisible(true);
            }
}

--- end import of Connections.java ---

End of Assignment 1



Begin Assignment 2


Creating an Assignment Data File
Create an interface that lets you enter a description of your Java lab assignments and the grades you receive, storing them in a file on your flash drive. Create a Submit button for the submission of each grade and a Done button to close the file.When you click the Done button, the Submit button should disappear and a Retrieve button should take its place. Use the Swing new Ocean Look and Feel. Add functionality to each button.

End Assignment 2


End of total project





Need Solution https://gum.co/iTDd