what does this method do???
Code:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
could you please tell me what does this method exactly do???
especially in this code
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Notepad extends JFrame implements ActionListener {
JTextArea myTextArea = new JTextArea ();
public static void main (String [] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Notepad frame = new Notepad ();
frame.showGraphicUserInterface();
AdjustmentListener adjustmentListener = new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
System.out.println("Adjusted: " + adjustmentEvent.getValue());
}
};
JScrollBar myscrollbar1 = new JScrollBar(JScrollBar.HORIZONTAL);
frame.add(myscrollbar1, BorderLayout.SOUTH);
myscrollbar1.addAdjustmentListener(adjustmentListener);
JScrollBar myscrollbar2 = new JScrollBar(JScrollBar.VERTICAL);
frame.add(myscrollbar2, BorderLayout.EAST);
myscrollbar2.addAdjustmentListener(adjustmentListener);
}
}
);
}
public Notepad () {
Container myPane = getContentPane();
setLayout(new BorderLayout());
myPane.add(myTextArea, BorderLayout.CENTER);
JMenuBar myMenu = new JMenuBar();
setJMenuBar(myMenu);
JMenu file = new JMenu("file");
myMenu.add(file);
JMenuItem open = new JMenuItem("Open");
file.add(open);
open.addActionListener(this);
JMenuItem saveAs = new JMenuItem("Save As");
file.add(saveAs);
saveAs.addActionListener(this);
JMenuItem exit = new JMenuItem("Exit");
file.add(exit);
exit.addActionListener(this);
JMenu edit = new JMenu("Font Size");
myMenu.add(edit);
JMenuItem undo = new JMenuItem("10");
edit.add(undo);
undo.addActionListener(this);
JMenuItem copy = new JMenuItem("20");
edit.add(copy);
copy.addActionListener(this);
JMenuItem paste = new JMenuItem("30");
edit.add(paste);
paste.addActionListener(this);
JMenuItem cut = new JMenuItem("40");
edit.add(cut);
cut.addActionListener(this);
JMenu BackgroundColor = new JMenu("Background Color");
myMenu.add(BackgroundColor);
JMenuItem red = new JMenuItem("Red");
BackgroundColor.add(red);
red.addActionListener(this);
red.setBackground(Color.red);
JMenuItem blue = new JMenuItem("Blue");
BackgroundColor.add(blue);
blue.addActionListener(this);
blue.setBackground(Color.blue);
JMenuItem lightGray = new JMenuItem("Light Gray");
BackgroundColor.add(lightGray);
lightGray.addActionListener(this);
lightGray.setBackground(Color.lightGray);
JMenuItem cyan = new JMenuItem("Cyan");
BackgroundColor.add(cyan);
cyan.addActionListener(this);
cyan.setBackground(Color.cyan);
JMenuItem white = new JMenuItem("White");
BackgroundColor.add(white);
white.addActionListener(this);
white.setBackground(Color.white);
Font myFont = new Font("Serif",Font.ITALIC,15);
myTextArea.setFont(myFont);
}
void showGraphicUserInterface() {
setTitle("Note Pad");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setSize(500,500);
}
public void actionPerformed(ActionEvent myEvent) {
String file = myEvent.getActionCommand();
String doc = " ";
if (file.equals("Exit")){
System.exit(0);
}
else if (file.equals("Open")){
Notepad frame = new Notepad ();
String filename = File.separator + "tmp";
JFileChooser fc = new JFileChooser(new File(filename));
// Show open dialog; this method does not return until the dialog is closed
fc.showOpenDialog(frame);
File selFile = fc.getSelectedFile();
}
else if (file.equals("Save As")){
Notepad frame = new Notepad ();
String filename = File.separator + "tmp";
JFileChooser fc = new JFileChooser(new File(filename));
// Show open dialog; this method does not return until the dialog is closed
fc.showSaveDialog(frame);
File selFile = fc.getSelectedFile();
}
else if (file.equals("10")){
Font myFont10 = new Font("Serif",Font.ITALIC,10);
myTextArea.setFont(myFont10);
}
else if (file.equals("20")){
Font myFont20 = new Font("Serif",Font.ITALIC,20);
myTextArea.setFont(myFont20);
}
else if (file.equals("30")){
Font myFont30 = new Font("Serif",Font.ITALIC,30);
myTextArea.setFont(myFont30);
}
else if (file.equals("40")){
Font myFont40 = new Font("Serif",Font.ITALIC,40);
myTextArea.setFont(myFont40);
}
else if (file.equals("Red")){
myTextArea.setBackground(Color.red);
}
else if (file.equals("Blue")){
myTextArea.setBackground(Color.blue);
}
else if (file.equals("Light Gray")){
myTextArea.setBackground(Color.lightGray);
}
else if (file.equals("Cyan")){
myTextArea.setBackground(Color.cyan);
}
else if (file.equals("White")){
myTextArea.setBackground(Color.white);
}
}
}