NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

FIG:12.15
##ButtonFrame

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ButtonFrame extends JFrame {

private final JButton plainButton;
private final JButton fancyButton;

public ButtonFrame() {
super("Testing Buttons");
setLayout(new FlowLayout());

plainButton = new JButton("Plain Button");
add(plainButton);

Icon bug1 = new ImageIcon(getClass().getResource("bug1.gif"));
Icon bug2 = new ImageIcon(getClass().getResource("bug2.gif"));
fancyButton = new JButton("Fancy Button", bug1);
fancyButton.setRolloverIcon(bug2);
add(fancyButton);

ButtonHandler handler = new ButtonHandler();
fancyButton.addActionListener(handler);
plainButton.addActionListener(handler);
}

private class ButtonHandler implements ActionListener {

@Override
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(ButtonFrame.this, String.format(
"You pressed: %s", event.getActionCommand()));
}
}
}


FIG:12.16
##ButtonTest

import javax.swing.JFrame;

public class ButtonTest {

public static void main(String[] args) {
ButtonFrame buttonFrame = new ButtonFrame();
buttonFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buttonFrame.setSize(275, 110);
buttonFrame.setVisible(true);

}
}


FIG:12.17
##CheckBoxFrame

import java.awt.Font;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JCheckBox;

public class CheckBoxFrame extends JFrame {

private final JTextField textField;
private final JCheckBox boldJCheckBox;
private final JCheckBox italicJCheckBox;

public CheckBoxFrame() {
super("CheckBox Test");
setLayout(new FlowLayout());

textField = new JTextField("Watch the font style change", 20);
textField.setFont(new Font("Serif", Font.PLAIN, 14));
add(textField);

boldJCheckBox = new JCheckBox("Bold");
italicJCheckBox = new JCheckBox("Italic");
add(boldJCheckBox);
add(italicJCheckBox);

CheckBoxHandler handler = new CheckBoxHandler();
boldJCheckBox.addItemListener(handler);
italicJCheckBox.addItemListener(handler);
}

private class CheckBoxHandler implements ItemListener {

@Override
public void itemStateChanged(ItemEvent event) {
Font font = null;
if (boldJCheckBox.isSelected() && italicJCheckBox.isSelected()) {
font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
} else if (boldJCheckBox.isSelected()) {
font = new Font("Serif", Font.BOLD, 14);
} else if (italicJCheckBox.isSelected()) {
font = new Font("Serif", Font.ITALIC, 14);
} else {
font = new Font("Serif", Font.PLAIN, 14);
}

textField.setFont(font);
}
}
}



FIG:12.18
##CheckBoxTest

import javax.swing.JFrame;

public class CheckBoxTest {

public static void main(String[] args) {
CheckBoxFrame checkBoxFrame = new CheckBoxFrame();
checkBoxFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
checkBoxFrame.setSize(275, 100);
checkBoxFrame.setVisible(true);
}
}


FIG:12.19
##RadioButtonFrame

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;

public class RadioButtonFrame extends JFrame {

private final JTextField textField;
private final Font plainFont;
private final Font boldFont;
private final Font italicFont;
private final Font boldItalicFont;
private final JRadioButton plainJRadioButton;
private final JRadioButton boldJRadioButton;
private final JRadioButton italicJRadioButton;
private final JRadioButton boldItalicJRadioButton;
private final ButtonGroup radioGroup;

public RadioButtonFrame() {
super("RadioButton Test");
setLayout(new FlowLayout());

textField = new JTextField("Watch the font style change", 25);
add(textField);

plainJRadioButton = new JRadioButton("Plain", true);
boldJRadioButton = new JRadioButton("Bold", false);
italicJRadioButton = new JRadioButton("Italic", false);
boldItalicJRadioButton = new JRadioButton("Bold/Italic", false);
add(plainJRadioButton);
add(boldJRadioButton);
add(italicJRadioButton);
add(boldItalicJRadioButton);
radioGroup = new ButtonGroup();
radioGroup.add(plainJRadioButton);
radioGroup.add(boldJRadioButton);
radioGroup.add(italicJRadioButton);
radioGroup.add(boldItalicJRadioButton);

plainFont = new Font("Serif", Font.PLAIN, 14);
boldFont = new Font("Serif", Font.BOLD, 14);
italicFont = new Font("Serif", Font.ITALIC, 14);
boldItalicFont = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
textField.setFont(plainFont);
plainJRadioButton.addItemListener(
new RadioButtonHandler(plainFont));
boldJRadioButton.addItemListener(
new RadioButtonHandler(boldFont));
italicJRadioButton.addItemListener(
new RadioButtonHandler(italicFont));
boldItalicJRadioButton.addItemListener(
new RadioButtonHandler(boldItalicFont));
}

private class RadioButtonHandler implements ItemListener {

private Font font;

public RadioButtonHandler(Font f) {
font = f;
}

@Override
public void itemStateChanged(ItemEvent event) {
textField.setFont(font);
}
}
}


FIG:12.20

##RadioButtonTest

import javax.swing.JFrame;

public class RadioButtonTest {

public static void main(String[] args) {
RadioButtonFrame radioButtonFrame = new RadioButtonFrame();
radioButtonFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
radioButtonFrame.setSize(300, 100);
radioButtonFrame.setVisible(true);
}
}




FIG:12.21
##ComboBoxFrame

import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ComboBoxFrame extends JFrame {

private final JComboBox<String> imagesJComboBox;
private final JLabel label;

private static final String[] names
= {"bug1.gif", "bug2.gif", "travelbug.gif", "buganim.gif"};
private final Icon[] icons = {
new ImageIcon(getClass().getResource(names[0])),
new ImageIcon(getClass().getResource(names[1])),
new ImageIcon(getClass().getResource(names[2])),
new ImageIcon(getClass().getResource(names[3]))};

public ComboBoxFrame() {
super("Testing JComboBox");
setLayout(new FlowLayout());

imagesJComboBox = new JComboBox<String>(names);
imagesJComboBox.setMaximumRowCount(3);

imagesJComboBox.addItemListener(
new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
label.setIcon(icons[imagesJComboBox.getSelectedIndex()]);
}
}
}
);

add(imagesJComboBox);
label = new JLabel(icons[0]);
add(label);
}
}


FIG:12.22
##ComboBoxFrameTest

import javax.swing.JFrame;

public class ComboBoxTest {

public static void main(String[] args) {
ComboBoxFrame comboBoxFrame = new ComboBoxFrame();
comboBoxFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
comboBoxFrame.setSize(350, 150);
comboBoxFrame.setVisible(true);
}
}


FIG:12.23
##ListFrame

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.