AWTandSwing

Add italic 11 declarations 31 32 33 34 35 36 37 38 39

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: lain", true ); c.add( plain ); bold = new JRadioButton( "Bold", false); c.add( bold ); italic = new JRadioButton( "Italic", false ); c.add( italic ); 1.1 Declarations 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 boldItalic = new JRadioButton( "Bold/Italic", false ); c.add( boldItalic ); // register events RadioButtonHandler handler = new RadioButtonHandler(); plain.addItemListener( handler ); Create a ButtonGroup. Only bold.addItemListener( handler ); one radio button in the group may italic.addItemListener( handler ); be selected at a time. boldItalic.addItemListener( handler ); // create logical relationship between JRadioButtons radioGroup = new ButtonGroup(); Method add adds radio radioGroup.add( plain ); buttons to the ButtonGroup radioGroup.add( bold ); radioGroup.add( italic ); radioGroup.add( boldItalic ); plainFont = new Font( "TimesRoman", Font.PLAIN, 14 ); boldFont = new Font( "TimesRoman", Font.BOLD, 14 ); italicFont = new Font( "TimesRoman", Font.ITALIC, 14 ); boldItalicFont = new Font( "TimesRoman", Font.BOLD + Font.ITALIC, 14 ); t.setFont( plainFont ); setSize( 300, 100 ); show(); } JList List Displays series of items may select one or more items Constructor JList( arrayOfNames ) Takes array of Objects (Strings) to display in list Class JList setVisibleRowCount( n ) Displays n items at a time Does not provide automatic scrolling 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 // create a list with the items in the colorNames array colorList = new JList( colorNames ); colorList.setVisibleRowCount( 5 ); // do not allow multiple selections colorList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); // add a JScrollPane containing the JList // to the content pane c.add( new JScrollPane( colorList ) ); Initialize JList with array of Strings, and show 5 items at a time. Make the JList a singleselection list....
View Full Document

Ask a homework question - tutors are online