JOptionPane.showMessageDialog(null, "Hello, World!");
JOptionPane.showMessageDialog(
null,
"Hello, World!",
"Message",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon("globe.gif"));
public interface Icon
{
int getIconWidth();
int getIconHeight();
void paintIcon(Component c, Graphics g, int x, int y);
}
int width = anIcon.getIconWidth();
showMessageDialog(..., new MarsIcon(50))
ArrayList<E> a = . . .
Collections.sort(a);
public interface Comparable<T>
{
int compareTo(T other);
}
public interface Comparator<T>
{
int compare(T obj1, T obj2);
}
Collections.sort(list, comp);
Collections.sort(countries,
new CountryComparatorByName());
Comparator<Country> comp = new
Comparator<Country>()
{
public int compare(Country country1, Country country2)
{
return country1.getName().compareTo(country2.getName());
}
};
JFrame frame = new JFrame();
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JButton helloButton = new JButton("Say Hello");
frame.setLayout(new FlowLayout());
frame.add(helloButton);
public interface ActionListener
{
int actionPerformed(ActionEvent event);
}
helloButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
textField.setText("Hello, World");
}
});
helloButton.addActionListener(listener);
listener.actionPerformed(event);
textField.setText("Hello, World!");
public static ActionListener createGreetingButtonListener(
final String message)
{
return new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
textField.setText(message);
}
};
}
public void paintIcon(Component c, Graphics g, int x, int y)
{
Graphics2D g2 = (Graphics2D)g;
. . .
}
Shape s = . . .;
g2.draw(s);
Point2D.Double start = new Point2D.Double(x1, y1);
Point2D.Double end = new Point2D.Double(x2, y2);
Shape segment = new Line2D.Double(start, end);
g2.draw(segment);
g2.fill(shape);