Example 1: Creating Jframe. Example 2: CenterFrame. Jaeki Song, Ph.D. Box Lubbock, TX, PH:

Size: px
Start display at page:

Download "Example 1: Creating Jframe. Example 2: CenterFrame. Jaeki Song, Ph.D. Box 42101 Lubbock, TX, 79409-2101 PH: 806 784 0435 [email protected]."

Transcription

1 Example 1: Creating Jframe import javax.swing.*; public class MyFrame public static void main(string[] args) JFrame frame = new JFrame("Test Frame"); frame.setsize(400, 300); frame.setvisible(true); frame.setdefaultcloseoperation( JFrame.EXIT_ON_CLOSE); Example 2: CenterFrame import javax.swing.*; import java.awt.*; public class CenterFrame public static void main(string[] args) JFrame frame = new JFrame("Centered Frame"); frame.setsize(400, 300); frame.setdefaultcloseoperation(jframe.exit_on_close); // Get the dimension of the screen Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); int screenwidth = screensize.width; int screenheight = screensize.height; // Get the dimension of the frame Dimension framesize = frame.getsize(); int x = (screenwidth - framesize.width)/2; int y = (screenheight - framesize.height)/2; frame.setlocation(x, y); frame.setvisible(true); 1

2 Example 3: Tax MyFrame.java import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.decimalformat; public class MyFrame extends JFrame JLabel labelsal, labeltr, labeltax; JTextField tfsal, tftr, tftax; JButton buttoncomp, buttonclear, buttonend; public MyFrame() Container c = getcontentpane(); //gets hold of the output screen c.setlayout(new GridLayout(5,2)); labelsal = new JLabel ("Enter your salary"); tfsal = new JTextField(); labeltr = new JLabel("Enter Tax rate here"); tftr= new JTextField(); labeltax = new JLabel("Your tax is: "); tftax = new JTextField(); buttoncomp = new JButton("Compute Tax"); buttonclear = new JButton("Clear"); buttonend = new JButton("End"); c.add(labelsal); c.add(tfsal); c.add(labeltr); c.add(tftr); c.add (labeltax); c.add(tftax); c.add(buttoncomp); c.add(buttonclear); c.add(buttonend); ButtonHandler handler = new ButtonHandler(); 2

3 buttoncomp.addactionlistener(handler); buttonclear.addactionlistener(handler); buttonend.addactionlistener(handler); pack(); setvisible(true); private class ButtonHandler implements ActionListener public void actionperformed (ActionEvent e) if (e.getsource() == buttoncomp) double sal, rate,tax; sal = Double.parseDouble(tfSal.getText()); rate =Double.parseDouble(tfTR.getText()); tax = sal * rate/100.0; DecimalFormat myfor = new DecimalFormat("0.00"); tftax.settext(string.valueof(myfor.format(tax))); if(e.getsource() == buttonclear) tfsal.settext(""); tftr.settext(""); tftax.settext(""); if(e.getsource() == buttonend) System.exit(0); MyApp.java public class MyApp public static void main (String args[]) MyFrame mytax= new MyFrame(); mytax.addwindowlistener( new WindowAdapter() public void windowclosing( WindowEvent e) System.exit(0); ); 3

4 Example 4: Inventory Create the GUI for an inventory application that calculates the number of textbooks received by a college bookstore. Application Requirements TTU bookstore receives cartons of textbooks. In each shipment, each carton contains the same number of textbooks. The inventory manger wants to use a compute to calculate the total number of textbooks arriving at the bookstore for each shipment. The inventory manage will enter the number of cartons received and the fixed number of textbooks in each carton of the shipment; the application should then calculate and display the total number of textbooks in the shipment Inventory.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Inventory extends JFrame private JLabel jlcartons; private JTextField jtfcartons; private JLabel jlitems; private JTextField jtfitems; private JLabel jltotal; private JTextField jtftotalresult; private JButton jbtcalculate; public Inventory() createuserinterface(); public void createuserinterface() 4

5 Container c = getcontentpane(); c.setlayout( null ); jlcartons = new JLabel(); jlcartons.settext( "Cartons per shipment:" ); jlcartons.setbounds( 16, 16, 130, 21 ); c.add( jlcartons ); jlitems = new JLabel(); jlitems.settext( "Items per carton:" ); jlitems.setbounds( 16, 48, 104, 21 ); c.add( jlitems ); // set up jltotal jltotal = new JLabel(); jltotal.settext( "Total:" ); jltotal.setbounds( 204, 16, 40, 21 ); c.add( jltotal ); // set up jtfcartons jtfcartons = new JTextField(); jtfcartons.settext( "0" ); jtfcartons.setbounds( 148, 16, 40, 21 ); jtfcartons.sethorizontalalignment( JTextField.RIGHT ); c.add( jtfcartons ); // set up jtfitems jtfitems = new JTextField(); jtfitems.settext( "0" ); jtfitems.setbounds( 148, 48, 40, 21 ); jtfitems.sethorizontalalignment( JTextField.RIGHT ); c.add( jtfitems ); // set up jtftotalresult jtftotalresult = new JTextField(); jtftotalresult.setbounds( 244, 16, 86, 21 ); jtftotalresult.sethorizontalalignment( JTextField.RIGHT ); jtftotalresult.seteditable( false ); c.add( jtftotalresult ); // set up jbtcalculate jbtcalculate = new JButton(); jbtcalculate.settext( "Calculate Total" ); jbtcalculate.setbounds( 204, 48, 126, 24 ); c.add( jbtcalculate ); ButtonHandler h = new ButtonHandler(); jbtcalculate.addactionlistener(h); settitle( "Inventory" ); // set title bar text setsize( 354, 112 ); // set window size 5

6 setvisible( true ); // display window public class ButtonHandler implements ActionListener public void actionperformed( ActionEvent e) if (e.getsource() == jbtcalculate) // multiply values input and display result in the text field jtftotalresult.settext( String.valueOf( Integer.parseInt( jtfcartons.gettext() ) * Integer.parseInt( jtfitems.gettext() ) ) ); // end method jbtcalculateactionperformed // end class Inventory MyApp.java class MyApp public static void main(string[] args) Inventory application = new Inventory(); 6

7 Example 5: Add List Class: Button Variable or Component Data Type Description Name txtdept TextField Input the department strdept String Store the department txtname TextField strname String txtphone TextField Input the phone extension strphone String Store the phone extension btnadd Button Add to phone list and clear fields txaphonelist TextArea Holds a list of names and phone numbers Methods Access Mode Return Type Method Name Pseudocode public void main Control the program Public Button Default constructor - Add components to the container Public Void actionperformed Transfer data from text boxes Concatenate the data Append line to text area Clear text fields Reset the focus 7

8 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Button extends JFrame //Declare components JTextField txtdept = new JTextField(20); JTextField txtname = new JTextField(20); JTextField txtphone = new JTextField(5); JTextArea txaphonelist = new JTextArea(10, 30); JButton btnadd = new JButton("Add to List"); //Declare variables String strdept; String strname; String strphone; public Button() //Place components to the Container Container c = getcontentpane(); c.setlayout(new BorderLayout()); JPanel p1 = new JPanel(); p1.setlayout(new GridLayout(4,2)); p1.add(new JLabel("Department: "), BorderLayout.NORTH); p1.add(txtdept, BorderLayout.NORTH); p1.add(new JLabel("Name: ")); p1.add(txtname); p1.add(new JLabel("Extension: ")); p1.add(txtphone); p1.add(btnadd); c.add(p1, BorderLayout.NORTH); c.add(txaphonelist, BorderLayout.CENTER); txtdept.requestfocus(); pack(); setvisible(true); //Add action listeners ButtonHandler handler= new ButtonHandler(); btnadd.addactionlistener(handler); public static void main (String args[]) Button MyApp = new Button(); MyApp.addWindowListener( new WindowAdapter( ) public void windowclosing(windowevent e) 8

9 System.exit(0); ); private class ButtonHandler implements ActionListener public void actionperformed(actionevent e) if (e.getsource()==btnadd) String stroutputline; //Declare local variable //Assign the text fields to variables strdept = txtdept.gettext(); strname = txtname.gettext(); strphone = txtphone.gettext(); //Concatenate the variables stroutputline = strdept + "\t" + strname + "\t" + strphone; //Append the concatenated line to the phone list txaphonelist.append(stroutputline + "\n"); //Clear the text fields txtdept.settext(""); txtname.settext(""); txtphone.settext(""); txtdept.requestfocus(); 9

10 Example 06: Car Payment System Application Requirements Typically, banks offer car loans for periods ranging from two to five years (24 to 60 months). Borrowers repay the loans in fixed monthly payments. The amount of each monthly payment is based on the length of the loan, the amount of borrowed and the interest rate. Create an application that allows the customer to enter the price of a car, the down payment amount and the annual interest rate of the loan. The application should display the loan s duration in months and the monthly payments for two-, three-, four-, and five-year loans Car payment system displays for loan lengths of two, three, four and five years. The above requirement indicates that the application must repeat a calculation four times- a repetition statement will be needed to solve this problem. CarPayment.java import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.decimalformat; public class CarPayment extends JFrame private JLabel jlprice; private JTextField jtfprice; private JLabel jldownpayment; 10

11 private JTextField jtfdownpayment; private JLabel jlinterest; private JTextField jtfinterest; private JButton jbtncalculate; private JTextArea jtapayments; public CarPayment() createuserinterface(); // create and position GUI components; register event handlers private void createuserinterface() // get content pane and set layout to null Container c = getcontentpane(); c.setlayout( null ); // set up jlprice jlprice = new JLabel(); jlprice.setbounds( 40, 24, 80, 21 ); jlprice.settext( "Price:" ); c.add( jlprice ); // set up jtfprice jtfprice = new JTextField(); jtfprice.setbounds( 184, 24, 56, 21 ); jtfprice.sethorizontalalignment( JTextField.RIGHT ); c.add( jtfprice ); // set up jldownpayment jldownpayment = new JLabel(); jldownpayment.setbounds( 40, 56, 96, 21 ); jldownpayment.settext( "Down payment:" ); c.add( jldownpayment ); // set up jtfdownpayment jtfdownpayment = new JTextField(); jtfdownpayment.setbounds( 184, 56, 56, 21 ); jtfdownpayment.sethorizontalalignment(jtextfield.right ); c.add( jtfdownpayment ); // set up jlinterest jlinterest = new JLabel(); jlinterest.setbounds( 40, 88, 120, 21 ); jlinterest.settext( "Annual interest rate:" ); c.add( jlinterest ); // set up jtfinterest 11

12 jtfinterest = new JTextField(); jtfinterest.setbounds( 184, 88, 56, 21 ); jtfinterest.sethorizontalalignment( JTextField.RIGHT ); c.add( jtfinterest ); // set up jbtncalculate and register its event handler jbtncalculate = new JButton(); jbtncalculate.setbounds( 92, 128, 94, 24 ); jbtncalculate.settext( "Calculate" ); c.add( jbtncalculate ); ButtonHandler h = new ButtonHandler(); jbtncalculate.addactionlistener(h); // set up jtapayments jtapayments = new JTextArea(); jtapayments.setbounds( 28, 168, 232, 90 ); jtapayments.seteditable( false ); c.add( jtapayments ); // set properties of application's window settitle( "Car Payment Calculator" ); // set title bar text setsize( 288, 302 ); // set window's size setvisible( true ); // display window // end method createuserinterface public class ButtonHandler implements ActionListener // method called when user clicks jbtncalculate public void actionperformed( ActionEvent e) int years = 2; // length of the loan in years int months; // payment period double monthlypayment; // monthly payment if (e.getsource()==jbtncalculate) // clear jtapayments jtapayments.settext( "" ); // add header to jtapayments jtapayments.append( "Months\tMonthly Payments" ); // retrieve user input int price = Integer.parseInt( jtfprice.gettext() ); int downpayment = Integer.parseInt( jtfdownpayment.gettext() ); double interest = Double.parseDouble( jtfinterest.gettext() ); // calculate loan amount and monthly interest int loanamount = price - downpayment; 12

13 double monthlyinterest = interest / 1200; // format to display monthlypayment in currency format DecimalFormat currency = new DecimalFormat( "$0.00" ); // while years is less than or equal to five years while ( years <= 5 ) // calculate payment period months = 12 * years; // get monthlypayment monthlypayment = calculatemonthlypayment(monthlyinterest, months, loanamount ); // insert result into jtapayments jtapayments.append( "\n" + months + "\t" + currency.format( monthlypayment ) ); years++; // increment counter // end while //end if statement // end method jbtncalculateactionperformed //end ButtonHandler class // method to clear JTextArea contents private void clearjtextarea() jtapayments.settext( "" ); // clear JTextArea contents // calculate monthlypayment private double calculatemonthlypayment( double monthlyinterest, int months, int loanamount ) double base = Math.pow( 1 + monthlyinterest, months ); return loanamount * monthlyinterest / ( 1 - ( 1 / base ) ); // end class CarPayment 13

14 Example 07: Detanl Application Application Requirements A dentist has asked you to create an application that employees can use to bill patients. Your application must allow the user to enter the patient s name and specify which services were performed during the visit. Your application must then calculate the total charges. If a user attempts to calculate the total of a bill before any services are specified or before the patient s name is entered, an error message should be displayed Pseudocode: When the user clicks the Calculate button: Obtain patient name for JTextField If user has not entered a patient name or has not selected any JCheckBoxes display error message in Dialog Else if Cleaning JCheckBox is selected Add cost of cleaning to total if Cavity Filling is selected Add cost of Cavity to total if X-Ray is selected add cost of X-ray total Display total price of services rendered in dollar format Action Component/class/object event Lable the application s components jlbdetalpaymentform, jlbpantionentname, jltotal, jlcleaningprice, jlcavityfilling, jlxrayprice, jcbcavityfilling, jcbcleaning, jcbxray, jbtncalcuate Obtain patient name for JTextField jtfpatientname user has not entered a patient name or has not selected any JCheckBoxes jcbcleaning, jcbcavityfilling, jcbxray display error message in Dialog JOptionPane Else jcbcleaning if Cleaning JCheckBox is selected Add cost of cleaning to total if Cavity Filling is selected jcbcavityfilling Add cost of Cavity to total if X-Ray is selected Add cost of X-ray total jcbxray Display total price of services rendered in dollar format jtftotal, dollar (DecimalFormat) 14

15 DentalPayment.java import java.awt.*; import java.awt.event.*; import java.text.*; import javax.swing.*; public class DentalPayment extends JFrame private JLabel jldentalpaymentform; private JLabel jlpatientname; private JTextField jtfpatientname; private JCheckBox jcbcleaning; private JLabel jlccleaningprice; private JCheckBox jcbcavityfilling; private JLabel jlcavityfillingprice; private JCheckBox jcbxray; private JLabel xraypricejlabel; private JLabel jltotal; private JTextField jtftotal; private JButton jbtncalculate; public DentalPayment() createuserinterface(); 15

16 private void createuserinterface() // get content pane for attaching GUI components Container c= getcontentpane(); // set up jldentalpaymentform jldentalpaymentform = new JLabel(); jldentalpaymentform.setbounds( 19, 19, 235, 28 ); jldentalpaymentform.settext( "Dental Payment Form" ); jldentalpaymentform.setfont(new Font( "Default", Font.PLAIN, 22 ) ); jldentalpaymentform.sethorizontalalignment(jlabel.center ); c.add( jldentalpaymentform ); // set up jlpatientname jlpatientname = new JLabel(); jlpatientname.setbounds( 19, 65, 91, 21 ); jlpatientname.settext( "Patient name:" ); c.add( jlpatientname ); // set up jtfpatientname jtfpatientname = new JTextField(); jtfpatientname.setbounds( 132, 65, 117, 21 ); c.add( jtfpatientname ); // set up jcbcleaning jcbcleaning = new JCheckBox(); jcbcleaning.setbounds( 16, 112, 122, 24 ); jcbcleaning.settext( "Cleaning" ); c.add( jcbcleaning ); // set up jlccleaningprice jlccleaningprice = new JLabel(); jlccleaningprice.setbounds( 211, 112, 38, 24 ); jlccleaningprice.settext( "$35" ); jlccleaningprice.sethorizontalalignment( JLabel.RIGHT ); c.add( jlccleaningprice ); // set up jcbcavityfilling jcbcavityfilling = new JCheckBox(); jcbcavityfilling.setbounds( 16, 159, 122, 24 ); jcbcavityfilling.settext( "Cavity Filling" ); c.add( jcbcavityfilling ); // set up jlcavityfillingprice jlcavityfillingprice = new JLabel(); jlcavityfillingprice.setbounds( 211, 159, 38, 24 ); jlcavityfillingprice.settext( "$150" ); jlcavityfillingprice.sethorizontalalignment(jlabel.right ); 16

17 c.add( jlcavityfillingprice ); // set up jcbxray jcbxray = new JCheckBox(); jcbxray.setbounds( 16, 206, 122, 24 ); jcbxray.settext( "X-Ray" ); c.add( jcbxray ); // set up xraypricejlabel xraypricejlabel = new JLabel(); xraypricejlabel.setbounds( 211, 206, 38, 24 ); xraypricejlabel.settext( "$85" ); xraypricejlabel.sethorizontalalignment( JLabel.RIGHT ); c.add( xraypricejlabel ); // set up jltotal jltotal = new JLabel(); jltotal.setbounds( 144, 256, 41, 21 ); jltotal.settext( "Total:" ); c.add( jltotal ); // set up jtftotal jtftotal = new JTextField(); jtftotal.setbounds( 192, 256, 56, 21 ); jtftotal.seteditable( false ); jtftotal.sethorizontalalignment( JTextField.CENTER ); c.add( jtftotal ); // set up jbtncalculate jbtncalculate = new JButton(); jbtncalculate.setbounds( 155, 296, 94, 24 ); jbtncalculate.settext( "Calculate" ); c.add( jbtncalculate ); ButtonHandler h = new ButtonHandler(); jbtncalculate.addactionlistener(h); settitle( "Dental Payment" ); // set title bar string setsize( 272, 364 ); // set window size setvisible( true ); // display window // calculate cost of patient's visit public class ButtonHandler implements ActionListener public void actionperformed( ActionEvent e) if (e.getsource()==jbtncalculate) String patient = jtfpatientname.gettext(); 17

18 // display error message if no name entered or no JCheckBox is selected if ( ( patient.equals( "" ) ) (!jcbcleaning.isselected() &&!jcbcavityfilling.isselected() &&!jcbxray.isselected() ) ) // display error message JOptionPane.showMessageDialog( null, "Please enter a name and check at least one item.", "Missing Information", JOptionPane.ERROR_MESSAGE ); else // otherwise, do calculations double total = 0.0; // if patient had a cleaning if ( jcbcleaning.isselected() ) total += 35; // if patient had cavity filled if ( jcbcavityfilling.isselected() ) total += 150; // if patient had x-ray taken if ( jcbxray.isselected() ) total += 85; DecimalFormat dollars = new DecimalFormat( "$0.00" ); jtftotal.settext( dollars.format( total ) ); // end else // end class DentalPayment MyApp.java class MyApp public static void main( String[] args ) DentalPayment application = new DentalPayment(); // end method main 18

19 Example 08: RadioButton import java.awt.*; import java.awt.event.*; import javax.swing.*; public class RadioButton extends JFrame private JTextField t; private JRadioButton plain, bold, italic; private Font plainfont, boldfont, italicfont; public RadioButton() super ("Radio Button"); Container c = getcontentpane(); c.setlayout(new FlowLayout()); t = new JTextField ("Font Change", 25); c.add(t); //Crate radio button plain = new JRadioButton ("Plain", true); c.add(plain); bold = new JRadioButton ("Bold", false); c.add(bold); italic = new JRadioButton ("Italic", false); c.add(italic); //Register event RadioButtonHandler handler=new RadioButtonHandler(); plain.additemlistener( handler); bold.additemlistener( handler); italic.additemlistener( handler); //Create logical relationship ButtonGroup radiogroup = new ButtonGroup(); radiogroup.add(plain); radiogroup.add(bold); radiogroup.add(italic); plainfont = new Font("TimesRoman", Font.PLAIN, 14); boldfont = new Font("TimesRoman", Font.BOLD, 14); italicfont = new Font("TimesRoman", Font.ITALIC, 14); t.setfont(plainfont); setsize(300,100); show(); public static void main(string args[]) 19

20 RadioButton MyApp = new RadioButton(); MyApp.addWindowListener( new WindowAdapter() public void windowclosing(windowevent e) System.exit(0); ); public class RadioButtonHandler implements ItemListener public void itemstatechanged (ItemEvent e) if(e.getsource() ==plain) t.setfont(plainfont); else if (e.getsource() ==bold) t.setfont(boldfont); else if (e.getsource () == italic) t.setfont(italicfont); t.repaint(); 20

21 Example 09:ComboBox This example creates a Swing application for EventHandlers Incorporated that allows the user to choose a party favor and displays the favor price. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JComboDemo extends JFrame JComboBox jcbbox; JLabel jllist, jlevent; JTextField jtfprice; JPanel p1, p2; int favorprice[ ] = 0, 725, 325, 125, 135; int totalprice = 0; String partyitem[ ] = "None", "Hats", "Streamers", "Noise Makers", "Ballons"; String output; int FavorNum; public JComboDemo() super ("JComboBox Demo"); Container c = getcontentpane(); c.setlayout(new BorderLayout()); p1 = new JPanel(); p1.setlayout(new GridLayout(1,2)); jllist = new JLabel("Favor List: "); p1.add(jllist); jcbbox = new JComboBox(partyItem); jcbbox.setmaximumrowcount(3); p1.add(jcbbox); c.add(p1, BorderLayout.NORTH); p2 = new JPanel(); p2.setlayout(new GridLayout(2,1)); jlevent = new JLabel("Event Handlers Incorporated"); p2.add(jlevent); jtfprice = new JTextField (10); p2.add(jtfprice); c.add(p2, BorderLayout.CENTER); 21

22 ItemHandler h = new ItemHandler( ); jcbbox.additemlistener(h); pack(); setvisible(true); public static void main (String args[]) JComboDemo app = new JComboDemo(); app.setdefaultcloseoperation(jframe.exit_on_close); public class ItemHandler implements ItemListener public void itemstatechanged(itemevent e) if (e.getstatechange( )== ItemEvent.SELECTED) int favornum = jcbbox.getselectedindex( ); totalprice = favorprice[favornum]; output = "Favor Price $ " + totalprice; jtfprice.settext (output); /* if (e.getsource( ) == jcbbox) int favornum = jcbbox.getselectedindex( ); totalprice = favorprice[favornum]; output = "Favor Price $ " + totalprice; jtfprice.settext (output); */ 22

23 Example10: JToolBar JToolBarDemo.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JToolBarDemo extends JFrame JTextArea jtaedit = new JTextArea (); JScrollPane scroll = new JScrollPane(jtaEdit, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); JPanel p1 = new JPanel(); ImageIcon image1 = new ImageIcon("Nam1.jpg"); ImageIcon image2 = new ImageIcon("Nam2.jpg"); ImageIcon image3 = new ImageIcon("Nam3.jpg"); JButton btnb1 = new JButton ("About Me", image1); JButton btnb2 = new JButton ("My Phone", image2); JButton btnb3 = new JButton ("My Address", image3); JToolBar bar = new JToolBar(); public JToolBarDemo() super("personal Information"); Container c = getcontentpane(); bar.add(btnb1); bar.add(btnb2); bar.add(btnb3); ButtonHandler h = new ButtonHandler(); btnb1.addactionlistener(h); btnb2.addactionlistener(h); btnb3.addactionlistener(h); p1.setlayout(new BorderLayout()); p1.add(bar, BorderLayout.NORTH); p1.add(scroll); c.add(p1); setsize(700, 300); setvisible(true); public class ButtonHandler implements ActionListener public void actionperformed(actionevent e) if (e.getsource() ==btnb1) jtaedit.append ("\n Daniel and David"); 23

24 else if (e.getsource()==btnb2) jtaedit.append("\n Hi All"); else if (e.getsource() == btnb3) jtaedit.append("\n I am Jaeki"); MyApp.java public class MyApp public static void main (String args[]) JToolBarDemo jt = new JToolBarDemo(); 24

25 Example 11: JList import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class List extends JFrame private JList colorlist; private Container c; private String colornames[] = "Cyan", "Magenta", "Yellow", "Black", "Blue", "Red" ; private Color colors[]= Color.cyan, Color.magenta, Color.yellow, Color.black, Color.blue, Color.red; public List() super("list"); c = getcontentpane(); c.setlayout(new FlowLayout()); //Create a list with teh items in the colornames array colorlist = new JList (colornames); colorlist.setvisiblerowcount(3); //do not allow multiple selections colorlist.setselectionmode(listselectionmodel.single_selection); //add a JscrollPane containing teh JList to teh content pane c.add (new JScrollPane(colorList)); ListHandler l = new ListHandler (); colorlist.addlistselectionlistener(l); setsize(250,150); show(); 25

26 public class ListHandler implements ListSelectionListener public void valuechanged(listselectionevent e) c.setbackground(colors[colorlist.getselectedindex()]); public static void main(string args[]) List MyApp = new List(); MyApp.addWindowListener( new WindowAdapter() public void windowclosing(windowevent e) System.exit(0); ); 26

27 Example 12: Menu 1. MenuApp.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MenuApp extends JFrame JFrame frmmenu; JLabel lblname; JMenuBar mnumain; JMenu mnufile, mnuedit, mnuhelp, mnueditcolor; JMenuItem mnufilesave, mnufileexit; JCheckBoxMenuItem mnueditbold; Font fntbold, fntplain; public MenuApp() Container c = getcontentpane(); //Declare components frmmenu = new JFrame("Menu Demo"); 27

28 lblname = new JLabel("Your Name"); fntbold = new Font("Times New Roman", Font.BOLD, 12); fntplain = new Font("Times New Roman", Font.PLAIN, 12); //Menu components mnumain = new JMenuBar(); mnufile = new JMenu("File"); mnuedit = new JMenu("Edit"); mnuhelp = new JMenu("Help"); mnueditcolor = new JMenu("Color"); //Menu items mnufilesave = new JMenuItem("Save"); mnufileexit = new JMenuItem("Exit"); mnueditbold = new JCheckBoxMenuItem("Bold", true); //Create the menu bar //File menu mnumain.add(mnufile); mnufile.add(mnufilesave); mnufilesave.setenabled(false); mnufile.addseparator(); ActionHandler handler1 = new ActionHandler(); mnufile.add(mnufileexit).addactionlistener(handler1); //Edit menu mnumain.add(mnuedit); mnuedit.addactionlistener(handler1); mnuedit.add(mnueditbold); ItemHandler handler2 = new ItemHandler(); mnueditbold.additemlistener(handler2); mnuedit.add(mnueditcolor); mnueditcolor.add("red").addactionlistener(handler1); mnueditcolor.add("blue").addactionlistener(handler1); mnueditcolor.add("green").addactionlistener(handler1); //Help menu mnumain.add(mnuhelp); mnuhelp.add(new JMenuItem("About")).addActionListener(handler1); //Attach the menu bar to the frame setjmenubar(mnumain); //Set up the components and the frame lblname.setfont(fntbold); c.add(lblname); private class ActionHandler implements ActionListener public void actionperformed(actionevent e) 28

29 //Determine which menu item was selected String strmenuitem = e.getactioncommand(); if (strmenuitem.equals("exit")) System.exit(0); //Exit to the operating system else if (strmenuitem.equals("red")) lblname.setforeground(color.red); else if (strmenuitem.equals("blue")) lblname.setforeground(color.blue); else if (strmenuitem.equals("green")) lblname.setforeground(color.green); else if (strmenuitem.equals("about")) AboutDialog frmabout = new AboutDialog(frmMenu); public class ItemHandler implements ItemListener public void itemstatechanged(itemevent event) //Determine state of Checkbox menu item int intstate = event.getstatechange(); if (intstate == event.selected) lblname.setfont(fntbold); else lblname.setfont(fntplain); 2. AboutDialog.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class AboutDialog extends Dialog JButton btnok = new JButton("OK"); JLabel lblprogrammer = new JLabel(" Programmer: Jaeki Song "); //Constructor public AboutDialog(Frame frmparent) super(frmparent, "About My Application", true); //Call the parent's constructor setlayout(new FlowLayout()); add(lblprogrammer); add(btnok); ButtonHandler handler3 = new ButtonHandler(); 29

30 btnok.addactionlistener(handler3); //Listen for close box addwindowlistener(new WindowAdapter() public void windowclosing(windowevent event) dispose(); //Destroy the dialog ); setsize(220, 100); show(); public class ButtonHandler implements ActionListener public void actionperformed(actionevent event) //Destroy the dialog when OK is pressed Object objsource = event.getsource(); if(objsource == btnok) dispose(); //Destroy the dialog 3. MyApp.java import java.awt.*; import java.awt.event.*; public class MyApp public static void main(string args[]) MenuApp mymenuapp = new MenuApp(); mymenuapp.setsize(400, 200); mymenuapp.setvisible(true); mymenuapp.addwindowlistener( new WindowAdapter() public void windowclosing(windowevent e) System.exit(0); ); 30

CS 335 Lecture 06 Java Programming GUI and Swing

CS 335 Lecture 06 Java Programming GUI and Swing CS 335 Lecture 06 Java Programming GUI and Swing Java: Basic GUI Components Swing component overview Event handling Inner classes and anonymous inner classes Examples and various components Layouts Panels

More information

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung AWT vs. Swing AWT (Abstract Window Toolkit; Package java.awt) Benutzt Steuerelemente des darunterliegenden Betriebssystems Native Code (direkt für die Maschine geschrieben, keine VM); schnell Aussehen

More information

Using A Frame for Output

Using A Frame for Output Eventos Roteiro Frames Formatting Output Event Handling Entering Data Using Fields in a Frame Creating a Data Entry Field Using a Field Reading Data in an Event Handler Handling Multiple Button Events

More information

The class JOptionPane (javax.swing) allows you to display a dialog box containing info. showmessagedialog(), showinputdialog()

The class JOptionPane (javax.swing) allows you to display a dialog box containing info. showmessagedialog(), showinputdialog() // Fig. 2.8: Addition.java An addition program import javax.swing.joptionpane; public class Addition public static void main( String args[] ) String firstnumber, secondnumber; int number1, number2, sum;

More information

Programming with Java GUI components

Programming with Java GUI components Programming with Java GUI components Java includes libraries to provide multi-platform support for Graphic User Interface objects. The multi-platform aspect of this is that you can write a program on a

More information

Graphical User Interfaces

Graphical User Interfaces M14_REGE1813_02_SE_C14.qxd 2/10/10 3:43 PM Page 822 Chapter14 Graphical User Interfaces 14.1 GUI Basics Graphical Input and Output with Option Panes Working with Frames Buttons, Text Fields, and Labels

More information

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program

More information

// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf;

// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf; // Correntista public class Correntista { String nome, sobrenome; int cpf; public Correntista(){ nome = "zé"; sobrenome = "Pereira"; cpf = 123456; public void setnome(string n){ nome = n; public void setsobrenome(string

More information

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012 GUIs with Swing Principles of Software Construction: Objects, Design, and Concurrency Jonathan Aldrich and Charlie Garrod Fall 2012 Slides copyright 2012 by Jeffrey Eppinger, Jonathan Aldrich, William

More information

Swing. A Quick Tutorial on Programming Swing Applications

Swing. A Quick Tutorial on Programming Swing Applications Swing A Quick Tutorial on Programming Swing Applications 1 MVC Model View Controller Swing is based on this design pattern It means separating the implementation of an application into layers or components:

More information

Advanced Network Programming Lab using Java. Angelos Stavrou

Advanced Network Programming Lab using Java. Angelos Stavrou Advanced Network Programming Lab using Java Angelos Stavrou Table of Contents A simple Java Client...3 A simple Java Server...4 An advanced Java Client...5 An advanced Java Server...8 A Multi-threaded

More information

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC). The Abstract Windowing Toolkit Since Java was first released, its user interface facilities have been a significant weakness The Abstract Windowing Toolkit (AWT) was part of the JDK form the beginning,

More information

How to Convert an Application into an Applet.

How to Convert an Application into an Applet. How to Convert an Application into an Applet. A java application contains a main method. An applet is a java program part of a web page and runs within a browser. I am going to show you three different

More information

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2; Lecture 15 The Game of "Craps" In the game of "craps" a player throws a pair of dice. If the sum on the faces of the pair of dice after the first toss is 7 or 11 the player wins; if the sum on the first

More information

Skills and Topics for TeenCoder: Java Programming

Skills and Topics for TeenCoder: Java Programming Skills and Topics for TeenCoder: Java Programming Our Self-Study Approach Our courses are self-study and can be completed on the student's own computer, at their own pace. You can steer your student in

More information

Java GUI Programming

Java GUI Programming Java GUI Programming Sean P. Strout ([email protected]) Robert Duncan ([email protected]) 10/24/2005 Java GUI Programming 1 Java has standard packages for creating custom Graphical User Interfaces What is a

More information

http://netbeans.org/kb/docs/java/gui-functionality.html?print=yes

http://netbeans.org/kb/docs/java/gui-functionality.html?print=yes Page 1 of 6 Introduction to GUI Building Contributed by Saleem Gul and Tomas Pavek, maintained by Ruth Kusterer and Irina Filippova This beginner tutorial teaches you how to create a simple graphical user

More information

Dev Articles 05/25/07 11:07:33

Dev Articles 05/25/07 11:07:33 Java Crawling the Web with Java Contributed by McGraw Hill/Osborne 2005 06 09 Access Your PC from Anywhere Download Your Free Trial Take your office with you, wherever you go with GoToMyPC. It s the remote

More information

Homework/Program #5 Solutions

Homework/Program #5 Solutions Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the

More information

GUI Components: Part 2

GUI Components: Part 2 GUI Components: Part 2 JComboBox and Using an Anonymous Inner Class for Event Handling A combo box (or drop-down list) enables the user to select one item from a list. Combo boxes are implemented with

More information

How To Build A Swing Program In Java.Java.Netbeans.Netcode.Com (For Windows) (For Linux) (Java) (Javax) (Windows) (Powerpoint) (Netbeans) (Sun) (

How To Build A Swing Program In Java.Java.Netbeans.Netcode.Com (For Windows) (For Linux) (Java) (Javax) (Windows) (Powerpoint) (Netbeans) (Sun) ( Chapter 11. Graphical User Interfaces To this point in the text, our programs have interacted with their users to two ways: The programs in Chapters 1-5, implemented in Processing, displayed graphical

More information

Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)

Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface) Fondamenti di Java Introduzione alla costruzione di GUI (graphic user interface) component - container - layout Un Container contiene [0 o +] Components Il Layout specifica come i Components sono disposti

More information

file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html

file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html file:c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html Seite 1 von 5 ScanCmds.java ------------------------------------------------------------------------------- ScanCmds Demontration

More information

Java GUI Programming. Building the GUI for the Microsoft Windows Calculator Lecture 2. Des Traynor 2005

Java GUI Programming. Building the GUI for the Microsoft Windows Calculator Lecture 2. Des Traynor 2005 Java GUI Programming Building the GUI for the Microsoft Windows Calculator Lecture 2 Des Traynor 2005 So, what are we up to Today, we are going to create the GUI for the calculator you all know and love.

More information

DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen

DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen DHBW Karlsruhe, Vorlesung Programmieren, Remote Musterlösungen Aufgabe 1 RMI - TimeService public interface TimeServerInterface extends Remote { public String gettime() throws RemoteException; import java.util.date;

More information

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2.

Lab 1A. Create a simple Java application using JBuilder. Part 1: make the simplest Java application Hello World 1. Start Jbuilder. 2. Lab 1A. Create a simple Java application using JBuilder In this lab exercise, we ll learn how to use a Java integrated development environment (IDE), Borland JBuilder 2005, to develop a simple Java application

More information

Programação Orientada a Objetos. Programando Interfaces Gráficas Orientadas a Objeto Parte 2

Programação Orientada a Objetos. Programando Interfaces Gráficas Orientadas a Objeto Parte 2 Programação Orientada a Objetos Programando Interfaces Gráficas Orientadas a Objeto Parte 2 Paulo André Castro CES-22 IEC - ITA Sumário Programando Interfaces Gráficas Orientadas a Objeto - Parte 2 2.2.1

More information

Lecture VII JAVA SWING GUI TUTORIAL

Lecture VII JAVA SWING GUI TUTORIAL 2. First Step: JFrame Lecture VII Page 1 Lecture VII JAVA SWING GUI TUTORIAL These notes are based on the excellent book, Core Java, Vol 1 by Horstmann and Cornell, chapter 7, graphics programming. Introduction

More information

How Scala Improved Our Java

How Scala Improved Our Java How Scala Improved Our Java Sam Reid PhET Interactive Simulations University of Colorado http://spot.colorado.edu/~reids/ PhET Interactive Simulations Provides free, open source educational science simulations

More information

Fachbereich Informatik und Elektrotechnik Java Swing. Advanced Java. Java Swing Programming. Programming in Java, Helmut Dispert

Fachbereich Informatik und Elektrotechnik Java Swing. Advanced Java. Java Swing Programming. Programming in Java, Helmut Dispert Java Swing Advanced Java Java Swing Programming Java Swing Design Goals The overall goal for the Swing project was: To build a set of extensible GUI components to enable developersto more rapidly develop

More information

Essentials of the Java(TM) Programming Language, Part 1

Essentials of the Java(TM) Programming Language, Part 1 Essentials of the Java(TM) Programming Language, Part 1 http://developer.java.sun.com/developer...ining/programming/basicjava1/index.html Training Index Essentials of the Java TM Programming Language:

More information

Lösningsförslag till tentamen 121217

Lösningsförslag till tentamen 121217 Uppgift 1 Lösningsförslag till tentamen 121217 a) Utskriften blir: a = 5 och b = 10 a = 5 och b = 10 b) Utskriften blir 1 2 3 4 5 5 2 3 4 1 c) Utskriften blir 321 Uppgift 2 Med användning av dialogrutor:

More information

Assignment # 2: Design Patterns and GUIs

Assignment # 2: Design Patterns and GUIs CSUS COLLEGE OF ENGINEERING AND COMPUTER SCIENCE Department of Computer Science CSc 133 Object-Oriented Computer Graphics Programming Spring 2014 John Clevenger Assignment # 2: Design Patterns and GUIs

More information

public class demo1swing extends JFrame implements ActionListener{

public class demo1swing extends JFrame implements ActionListener{ import java.io.*; import java.net.*; import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class demo1swing extends JFrame implements ActionListener JButton demodulacion;

More information

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus 1. Purpose This assignment exercises how to write a peer-to-peer communicating program using non-blocking

More information

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane. Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:

More information

Callbacks. Callbacks Copyright 2007 by Ken Slonneger 1

Callbacks. Callbacks Copyright 2007 by Ken Slonneger 1 Callbacks Callbacks refer to a mechanism in which a library or utility class provides a service to clients that are unknown to it when it is defined. Suppose, for example, that a server class creates a

More information

Tutorial Reference Manual. Java WireFusion 4.1

Tutorial Reference Manual. Java WireFusion 4.1 Tutorial Reference Manual Java WireFusion 4.1 Contents INTRODUCTION...1 About this Manual...2 REQUIREMENTS...3 User Requirements...3 System Requirements...3 SHORTCUTS...4 DEVELOPMENT ENVIRONMENT...5 Menu

More information

Karsten Lentzsch JGoodies SWING WITH STYLE

Karsten Lentzsch JGoodies SWING WITH STYLE Karsten Lentzsch JGoodies SWING WITH STYLE JGoodies: Karsten Lentzsch Open source Swing libraries Example applications Consultant for Java desktop Design assistance Training for visual design and implementation

More information

JIDE Common Layer Developer Guide (Open Source Project)

JIDE Common Layer Developer Guide (Open Source Project) JIDE Common Layer Developer Guide (Open Source Project) Contents PURPOSE OF THIS DOCUMENT... 4 WHY USING COMPONENTS... 4 WHY DO WE OPEN SOURCE... 5 HOW TO LEARN JIDE COMMON LAYER... 5 PACKAGE STRUCTURE...

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Extending Desktop Applications to the Web

Extending Desktop Applications to the Web Extending Desktop Applications to the Web Arno Puder San Francisco State University Computer Science Department 1600 Holloway Avenue San Francisco, CA 94132 [email protected] Abstract. Web applications have

More information

Tema: Encriptación por Transposición

Tema: Encriptación por Transposición import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PrincipalSO extends JApplet implements ActionListener { // Declaración global JLabel lblclave, lblencriptar, lblencriptado,

More information

Artificial Intelligence. Class: 3 rd

Artificial Intelligence. Class: 3 rd Artificial Intelligence Class: 3 rd Teaching scheme: 4 hours lecture credits: Course description: This subject covers the fundamentals of Artificial Intelligence including programming in logic, knowledge

More information

LAYOUT MANAGERS. Layout Managers Page 1. java.lang.object. java.awt.component. java.awt.container. java.awt.window. java.awt.panel

LAYOUT MANAGERS. Layout Managers Page 1. java.lang.object. java.awt.component. java.awt.container. java.awt.window. java.awt.panel LAYOUT MANAGERS A layout manager controls how GUI components are organized within a GUI container. Each Swing container (e.g. JFrame, JDialog, JApplet and JPanel) is a subclass of java.awt.container and

More information

Tutorial: Time Of Day Part 2 GUI Design in NetBeans

Tutorial: Time Of Day Part 2 GUI Design in NetBeans Tutorial: Time Of Day Part 2 GUI Design in NetBeans October 7, 2010 Author Goals Kees Hemerik / Gerard Zwaan Getting acquainted with NetBeans GUI Builder Illustrate the separation between GUI and computation

More information

Essentials of the Java Programming Language

Essentials of the Java Programming Language Essentials of the Java Programming Language A Hands-On Guide by Monica Pawlan 350 East Plumeria Drive San Jose, CA 95134 USA May 2013 Part Number TBD v1.0 Sun Microsystems. Inc. All rights reserved If

More information

JIDE Action Framework Developer Guide

JIDE Action Framework Developer Guide JIDE Action Framework Developer Guide Contents PURPOSE OF THIS DOCUMENT... 1 WHAT IS JIDE ACTION FRAMEWORK... 1 PACKAGES... 3 MIGRATING FROM EXISTING APPLICATIONS... 3 DOCKABLEBARMANAGER... 9 DOCKABLE

More information

JiST Graphical User Interface Event Viewer. Mark Fong [email protected]

JiST Graphical User Interface Event Viewer. Mark Fong mjf21@cornell.edu JiST Graphical User Interface Event Viewer Mark Fong [email protected] Table of Contents JiST Graphical User Interface Event Viewer...1 Table of Contents...2 Introduction...3 What it does...3 Design...3

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

Remote Method Invocation

Remote Method Invocation Goal of RMI Remote Method Invocation Implement distributed objects. Have a program running on one machine invoke a method belonging to an object whose execution is performed on another machine. Remote

More information

method is never called because it is automatically called by the window manager. An example of overriding the paint() method in an Applet follows:

method is never called because it is automatically called by the window manager. An example of overriding the paint() method in an Applet follows: Applets - Java Programming for the Web An applet is a Java program designed to run in a Java-enabled browser or an applet viewer. In a browser, an applet is called into execution when the APPLET HTML tag

More information

Mouse Event Handling (cont.)

Mouse Event Handling (cont.) GUI Components: Part II Mouse Event Handling (cont.) Each mouse event-handling method receives a MouseEvent object that contains information about the mouse event that occurred, including the x- and y-coordinates

More information

Principles of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad 15-214. Spring 2013

Principles of Software Construction: Objects, Design and Concurrency. GUIs with Swing. toad 15-214. Spring 2013 Principles of Software Construction: Objects, Design and Concurrency GUIs with Swing 15-214 toad Spring 2013 Christian Kästner Charlie Garrod School of Computer Science 2012-13 C Garrod, C Kästner, J Aldrich,

More information

Java Appletek II. Applet GUI

Java Appletek II. Applet GUI THE INTERNET,mapped on the opposite page, is a scalefree network in that Java Appletek II. dis.'~tj port,from BYALBERTU\SZLOBARABASI ANDERICBONABEAU THE INTERNET,mapped on the opposite page, is a scalefree

More information

Lab 9. Spam, Spam, Spam. Handout 11 CSCI 134: Spring, 2015. To gain experience with Strings. Objective

Lab 9. Spam, Spam, Spam. Handout 11 CSCI 134: Spring, 2015. To gain experience with Strings. Objective Lab 9 Handout 11 CSCI 134: Spring, 2015 Spam, Spam, Spam Objective To gain experience with Strings. Before the mid-90s, Spam was a canned meat product. These days, the term spam means just one thing unwanted

More information

Analysis Of Source Lines Of Code(SLOC) Metric

Analysis Of Source Lines Of Code(SLOC) Metric Analysis Of Source Lines Of Code(SLOC) Metric Kaushal Bhatt 1, Vinit Tarey 2, Pushpraj Patel 3 1,2,3 Kaushal Bhatt MITS,Datana Ujjain 1 [email protected] 2 [email protected] 3 [email protected]

More information

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account). IRA EXAMPLES This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account). Definite Counting Loop Example IRA After x Years This first example illustrates

More information

Course/Year W080/807 Expected Solution Subject: Software Development to Question No: 1

Course/Year W080/807 Expected Solution Subject: Software Development to Question No: 1 Subject: Software Development to Question No: 1 Page 1 of 2 Allocation: 33 marks (a) (i) A layout manager is an object that implements the LayoutManager interface and determines the size and position of

More information

The Basic Java Applet and JApplet

The Basic Java Applet and JApplet I2PUJ4 - Chapter 6 - Applets, HTML, and GUI s The Basic Java Applet and JApplet Rob Dempster [email protected] School of Computer Science University of KwaZulu-Natal Pietermaritzburg Campus I2PUJ4 - Chapter

More information

@ - Internal # - External @- Online TH PR OR TW TOTAL HOURS 04 --- 04 03 100 50# --- 25@ 175

@ - Internal # - External @- Online TH PR OR TW TOTAL HOURS 04 --- 04 03 100 50# --- 25@ 175 COURSE NAME : COMPUTER ENGINEERING GROUP COURSE CODE SEMESTER SUBJECT TITLE : CO/CM/IF/CD : SIXTH : ADVANCED JAVA PROGRAMMING SUBJECT CODE : Teaching and Examination Scheme: @ - Internal # - External @-

More information

OBJECT ORIENTED PROGRAMMING IN JAVA EXERCISES

OBJECT ORIENTED PROGRAMMING IN JAVA EXERCISES OBJECT ORIENTED PROGRAMMING IN JAVA EXERCISES CHAPTER 1 1. Write Text Based Application using Object Oriented Approach to display your name. // filename: Name.java // Class containing display() method,

More information

Nexawebホワイトペーパー. Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability

Nexawebホワイトペーパー. Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability Nexawebホワイトペーパー Developing with Nexaweb ~ Nexaweb to Improve Development Productivity and Maintainability Nexaweb Technologies, Inc. February 2012 Overview Many companies today are creating rich internet

More information

Simple Line Drawing. Description of the Simple Line Drawing program

Simple Line Drawing. Description of the Simple Line Drawing program Simple Line Drawing Description of the Simple Line Drawing program JPT Techniques Creating and using the ColorView Creating and using the TextAreaView Creating and using the BufferedPanel with graphics

More information

Software Design: Figures

Software Design: Figures Software Design: Figures Today ColorPicker Layout Manager Observer Pattern Radio Buttons Prelimiary Discussion Exercise 5 ColorPicker They don't teach you the facts of death, Your mum and dad. They give

More information

Using NetBeans IDE for Desktop Development. Geertjan Wielenga http://blogs.sun.com/geertjan

Using NetBeans IDE for Desktop Development. Geertjan Wielenga http://blogs.sun.com/geertjan Using NetBeans IDE for Desktop Development Geertjan Wielenga http://blogs.sun.com/geertjan Agenda Goals Design: Matisse GUI Builder Medium Applications: JSR-296 Tooling Large Applications: NetBeans Platform

More information

Object Oriented Programming with Java. School of Computer Science University of KwaZulu-Natal

Object Oriented Programming with Java. School of Computer Science University of KwaZulu-Natal Object Oriented Programming with Java School of Computer Science University of KwaZulu-Natal January 30, 2006 2 Object Oriented Programming with Java Notes for the Computer Science Module Object Oriented

More information

CS108, Stanford Handout #33. Sockets

CS108, Stanford Handout #33. Sockets CS108, Stanford Handout #33 Fall, 2007-08 Nick Parlante Sockets Sockets Sockets make network connections between machines, but you just read/write/block on them like there were plain file streams. The

More information

WRITING DATA TO A BINARY FILE

WRITING DATA TO A BINARY FILE WRITING DATA TO A BINARY FILE TEXT FILES VS. BINARY FILES Up to now, we have looked at how to write and read characters to and from a text file. Text files are files that contain sequences of characters.

More information

Konzepte objektorientierter Programmierung

Konzepte objektorientierter Programmierung Konzepte objektorientierter Programmierung Prof. Dr. Peter Müller Werner Dietl Software Component Technology Exercises 5: Frameworks Wintersemester 05/06 2 Homework 1 Observer Pattern From: Gamma, Helm,

More information

core 2 Handling Mouse and Keyboard Events

core 2 Handling Mouse and Keyboard Events core Web programming Handling Mouse and Keyboard Events 1 2001-2003 Marty Hall, Larry Brown http:// Agenda General event-handling strategy Handling events with separate listeners Handling events by implementing

More information

Mapping to the Windows Presentation Framework

Mapping to the Windows Presentation Framework Mapping to the Windows Presentation Framework This section maps the main IFML concepts to the.net Windows Presentation Framework (WFP). Windows Presentation Framework (WPF) is a part of.net Framework by

More information

GOPAL RAMALINGAM MEMORIAL ENGINEERING COLLEGE. Rajeshwari nagar, Panapakkam, Near Padappai, Chennai-601301.

GOPAL RAMALINGAM MEMORIAL ENGINEERING COLLEGE. Rajeshwari nagar, Panapakkam, Near Padappai, Chennai-601301. GOPAL RAMALINGAM MEMORIAL ENGINEERING COLLEGE Rajeshwari nagar, Panapakkam, Near Padappai, Chennai-601301. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING OOAD LAB MANUAL Sub. Code/Sub. Name: CS2357-Object

More information

Developing GUI Applications: Architectural Patterns Revisited

Developing GUI Applications: Architectural Patterns Revisited Developing GUI Applications: Architectural Patterns Revisited A Survey on MVC, HMVC, and PAC Patterns Alexandros Karagkasidis [email protected] Abstract. Developing large and complex GUI applications

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

Appendix B Task 2: questionnaire and artefacts

Appendix B Task 2: questionnaire and artefacts Appendix B Task 2: questionnaire and artefacts This section shows the questionnaire, the UML class and sequence diagrams, and the source code provided for the task 1 (T2) Buy a Ticket Unsuccessfully. It

More information

ICOM 4015: Advanced Programming

ICOM 4015: Advanced Programming ICOM 4015: Advanced Programming Lecture 10 Reading: Chapter Ten: Inheritance Copyright 2009 by John Wiley & Sons. All rights reserved. Chapter 10 Inheritance Chapter Goals To learn about inheritance To

More information

Specialized Programme on Web Application Development using Open Source Tools

Specialized Programme on Web Application Development using Open Source Tools Specialized Programme on Web Application Development using Open Source Tools Objective: At the end of the course, Students will be able to: Understand various open source tools(programming tools and databases)

More information

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé. http://www.rzo.free.fr

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé. http://www.rzo.free.fr Cours de Java Sciences-U Lyon Java - Introduction Java - Fondamentaux Java Avancé http://www.rzo.free.fr Pierre PARREND 1 Octobre 2004 Sommaire Java Introduction Java Fondamentaux Java Avancé GUI Graphical

More information

GUI Event-Driven Programming

GUI Event-Driven Programming GUI Event-Driven Programming CSE 331 Software Design & Implementation Slides contain content by Hal Perkins and Michael Hotan 1 Outline User events and callbacks Event objects Event listeners Registering

More information

Sample Turtle Programs

Sample Turtle Programs Sample Turtle Programs Sample 1: Drawing a square This program draws a square. Default values are used for the turtle s pen color, pen width, body color, etc. import galapagos.*; /** * This sample program

More information

FRONTPAGE FORMS... ... ...

FRONTPAGE FORMS... ... ... tro FRONTPAGE FORMS........................................ CREATE A FORM.................................................................................. 1. Open your web and create a new page. 2. Click

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

11. Applets, normal window applications, packaging and sharing your work

11. Applets, normal window applications, packaging and sharing your work 11. Applets, normal window applications, packaging and sharing your work In this chapter Converting Full Screen experiments into normal window applications, Packaging and sharing applications packaging

More information

Chapter 28.9. Building a Game Pad Controller with JInput

Chapter 28.9. Building a Game Pad Controller with JInput Chapter 28.9. Building a Game Pad Controller with JInput Playing PC games with a keyboard and mouse can sometimes feel like playing tennis in a tuxedo entirely possible but not quite right. Wouldn't it

More information

TATJA: A Test Automation Tool for Java Applets

TATJA: A Test Automation Tool for Java Applets TATJA: A Test Automation Tool for Java Applets Matthew Xuereb 19, Sanctuary Street, San Ġwann [email protected] Abstract Although there are some very good tools to test Web Applications, such tools neglect

More information

How To Write A Program For The Web In Java (Java)

How To Write A Program For The Web In Java (Java) 21 Applets and Web Programming As noted in Chapter 2, although Java is a general purpose programming language that can be used to create almost any type of computer program, much of the excitement surrounding

More information

Maximizing the Use of Slide Masters to Make Global Changes in PowerPoint

Maximizing the Use of Slide Masters to Make Global Changes in PowerPoint Maximizing the Use of Slide Masters to Make Global Changes in PowerPoint This document provides instructions for using slide masters in Microsoft PowerPoint. Slide masters allow you to make a change just

More information

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

More information

CS211 Spring 2005 Final Exam May 17, 2005. Solutions. Instructions

CS211 Spring 2005 Final Exam May 17, 2005. Solutions. Instructions CS11 Spring 005 Final Exam May 17, 005 Solutions Instructions Write your name and Cornell netid above. There are 15 questions on 1 numbered pages. Check now that you have all the pages. Write your answers

More information

An Overview of Java. overview-1

An Overview of Java. overview-1 An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2

More information

Here's the code for our first Applet which will display 'I love Java' as a message in a Web page

Here's the code for our first Applet which will display 'I love Java' as a message in a Web page Create a Java Applet Those of you who purchased my latest book, Learn to Program with Java, know that in the book, we create a Java program designed to calculate grades for the English, Math and Science

More information

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9. Working with Tables in Microsoft Word The purpose of this document is to lead you through the steps of creating, editing and deleting tables and parts of tables. This document follows a tutorial format

More information

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION Tao Chen 1, Tarek Sobh 2 Abstract -- In this paper, a software application that features the visualization of commonly used

More information

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++ MS Visual C++ Introduction 1 Quick Introduction The following pages provide a quick tutorial on using Microsoft Visual C++ 6.0 to produce a small project. There should be no major differences if you are

More information

Java is commonly used for deploying applications across a network. Compiled Java code

Java is commonly used for deploying applications across a network. Compiled Java code Module 5 Introduction to Java/Swing Java is commonly used for deploying applications across a network. Compiled Java code may be distributed to different machine architectures, and a native-code interpreter

More information