Java Reference
In-Depth Information
fontComboBox. setSelectedItem( "SansSerif" );
final JComboBox sizeComboBox = new JComboBox ( ) ;
final JCheckBox boldCheckBox = new JCheckBox( "Bold" );
final JCheckBox italicCheckBox = new JCheckBox( "Italic" );
for ( int i=8;i < = 72; i++) {
sizeComboBox . addItem( i ) ;
sizeComboBox. setSelectedItem(12) ;
sizeComboBox . setEditable ( true );
ActionListener changeListener = new ActionListener ()
{
{
public void actionPerformed(ActionEvent e)
int mask = Font .PLAIN;
if (boldCheckBox . isSelected () )
{
mask += Font .BOLD;
if (italicCheckBox . isSelected ())
{
mask += Font . ITALIC;
textArea . setFont( new Font((String) fontComboBox. getSelectedItem
() , mask, (Integer) sizeComboBox. getSelectedItem())) ;
}
} ;
controlPanel . add( fontComboBox) ;
controlPanel .add(sizeComboBox) ;
controlPanel . add(boldCheckBox) ;
controlPanel .add(italicCheckBox) ;
add( controlPanel , BorderLayout .NORTH) ;
boldCheckBox. addActionListener(changeListener) ;
italicCheckBox . addActionListener(changeListener) ;
sizeComboBox. addActionListener(changeListener) ;
fontComboBox. addActionListener(changeListener) ;
openMenuItem. addActionListener( new ActionListener ()
{
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser () ;
if ( f i leChooser . showDialog (NotepadFrame . this , "Open" )==
JFileChooser .APPROVEOPTION) {
File newFile = fileChooser . getSelectedFile() ;
try (Scanner fileHandler = new Scanner(newFile))
{
textArea . setText( "" );
while ( fileHandler . hasNext () )
{
String line = fileHandler .nextLine() ;
textArea . append( l ine + "\n" );
}
}
catch (Exception exception) {
}
}
}
} );
JMenuItem saveMenuItem = new JMenuItem( "Save..." );
fileMenu .add(saveMenuItem) ;
saveMenuItem. addActionListener( new ActionListener ()
{
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser () ;
 
Search WWH ::




Custom Search