


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Some Graphical User Interface Elements in JavaCalin Curescu
Calin Curescu
TDDC32 lecture 2, 200620 pages
Reusing old TDDB32 slides by Peter Loborg, Tommy Olsson
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 20062 of 20
import javax.swing.*; class GuiDiemo { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Hi folks!"); } }
int option = JOptionPane.showConfirmDialog(null, "Maybe...", "Is this acceptable?", JOptionPane.YES_NO_CANCEL_OPTION);
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 20063 of 20
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 20064 of 20
import java.awt.; import java.awt.event.; import javax.swing.*; public class WidgetDemo { public static void main(String[] args) { JFrame window = new JFrame("Easy..."); Container content = window.getContentPane(); content.setLayout(new BorderLayout()); JLabel label = new JLabel("...isn't it?"); content.add(label, "Center"); JPanel content2 = new JPanel(); content2.setLayout(new FlowLayout()); content2.add(new JButton("...")); content2.add(new JButton("...no way!")); content.add(content2, "South"); window.pack(); window.show(); } }
class MyListener implements ActionListener { public void actionPerformed(ActionEvent e) { System.println(e); } } ... guiObj.addActionListener(new MyListener());
guiObj.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.println(e); } }); //<== Observe the paranteses
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 20067 of 20
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 20068 of 20
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 20069 of 20
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 200610 of 20
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 200619 of 20
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 200620 of 20
Some Graphical User Interface Elements in JavaCalin Curescu TDDC32 lecture 2, 200621 of 20