20- Graphical user interface java

279 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
279
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

20- Graphical user interface java

  1. 1. Graphical User Interface JAVA FOUNDATION CLASS (JFC) – JAVAX.SWING
  2. 2. JFC - Swing  Swing is part of the so-called "Java Foundation Classes (JFC)"  Introduced in 1997 after the release of JDK 1.1.  JFC was subsequently included as an integral part of JDK since JDK 1.2. JFC consists of: ◦ Swing API: for advanced graphical programming. ◦ Accessibility API: provides assistive technology for the disabled. ◦ Java 2D API: for high quality 2D graphics and images. ◦ Pluggable look and feel supports. ◦ Drag-and-drop support between Java and native applications.
  3. 3. 3 Swing Components Containers ◦ Contain and manage other components. ◦ Top Level/Internal ◦ Examples: JFrame (Top Level), JScrollPane, JPanel. Basic controls ◦ Atomic components ◦ Used for showing output and/or getting some input ◦ Inherits JComponent ◦ Examples: JButton, JLabel, JTextArea, JTable, Jlist Usually every Swing class extends the corresponding AWT class ◦ For backward-compatibility reasons
  4. 4. 4 JFrame Made of several layers Widgets are added to the Content Pane layer. ◦ Use getContentPane() to obtain it Other layers are used for customizing the window's appearence
  5. 5. The JFrame Class import javax.swing.JFrame; class MyFrame extends JFrame{ MyFrame(){ setSize(300,300); setTitle("My Frame - HIST"); setVisible(true); } public static void main(String args[]){ new MyFrame(); } }
  6. 6. The JFrame Class import javax.swing.JFrame; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setVisible(true); } }
  7. 7. The JDialog Class import javax.swing.JDialog; import javax.swing.JFrame; class MyDialog { public static void main(String args[]){ JDialog dialog = new JDialog(new JFrame(),"My Dialog - HIST"); dialog.setSize(300,300); dialog.setVisible(true); } }
  8. 8. The JPanel Class import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Color; class MyPannelFrame extends JFrame{ MyPannelFrame(){ setSize(300,300); setTitle("My Frame - HIST"); setVisible(true); JPanel panel = new JPanel(); panel.setBackground(Color.BLACK); add(panel); } public static void main(String args[]){ new MyPannelFrame(); } }
  9. 9. import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Color; class MyPannelFrame extends JFrame{ MyPannelFrame(){ setSize(300,300); setLayout(null); setTitle("My Frame - HIST"); setVisible(true); JPanel panel1 = new JPanel(); panel1.setBackground(Color.BLACK); panel1.setBounds(0,0,150,300); add(panel1); JPanel panel2 = new JPanel(); panel2.setBackground(Color.YELLOW); panel2.setBounds(150,0,150,300); add(panel2); } public static void main(String args[]){ new MyPannelFrame(); } } The Absolute Layout
  10. 10. The Absolute Layout
  11. 11. The GridLayout import javax.swing.*; import java.awt.*; class MyPannelFrame extends JFrame{ MyPannelFrame(){ setSize(300,300); setLayout(new GridLayout(0,2)); setTitle("My Frame - HIST"); setVisible(true); JPanel panel1 = new JPanel(); panel1.setBackground(Color.RED); add(panel1); JPanel panel2 = new JPanel(); panel2.setBackground(Color.YELLOW); panel2.setBounds(150,0,150,300); add(panel2); JPanel panel3 = new JPanel(); panel3.setBackground(Color.GREEN); add(panel3); } public static void main(String args[]){ new MyPannelFrame(); } }
  12. 12. The GridLayout
  13. 13. The Jbutton Class import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); JButton button = new JButton("Click!"); button.setBounds(10,10,100,30); frame.add(button); frame.setVisible(true); } }
  14. 14. The JTextField Class import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); JTextField text = new JTextField(); text.setBounds(10,10,100,30); frame.add(text); frame.setVisible(true); } }
  15. 15. import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); JLabel label = new JLabel("My Label - HIST"); label.setBounds(10,10,100,30); frame.add(label); frame.setVisible(true); } } The JLabel Class
  16. 16. The JTextArea Class import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); JTextArea tArea = new JTextArea(); tArea.setBounds(10,10,200,100); frame.add(tArea); frame.setVisible(true); } } `
  17. 17. The JMenuBar, JMenu & JMenuItem Classes import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); JMenuItem New = new JMenuItem("New"); JMenuItem Open = new JMenuItem("Open"); JMenuItem Save = new JMenuItem("Save"); JMenu file = new JMenu("File"); file.add(New); file.add(Open); file.add(Save); JMenuBar mbar = new JMenuBar(); mbar.add(file); frame.setJMenuBar(mbar); frame.setVisible(true); } }
  18. 18. The JList Class import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); String subj[] = {"ASP","PHP","Java"}; JList<String> list = new JList<>(subj); list.setBounds(20,20,100,150); frame.add(list); frame.setVisible(true); } }
  19. 19. The JComboBox Class import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); String subj[] = {"ASP","PHP","Java"}; JComboBox<String> combo = new JComboBox<>(subj); combo.setBounds(20,20,100,20); frame.add(combo); frame.setVisible(true); } }
  20. 20. The JCheckBox Class import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); JCheckBox chkb1 = new JCheckBox("JAVA"); chkb1.setBounds(20,20,100,20); frame.add(chkb1); JCheckBox chkb2 = new JCheckBox("ASP"); chkb2.setBounds(20,40,100,20); frame.add(chkb2); JCheckBox chkb3 = new JCheckBox("PHP"); chkb3.setBounds(20,60,100,20); frame.add(chkb3); frame.setVisible(true); } }
  21. 21. The JRadioButton Class import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); frame.setLayout(null); JRadioButton r1 = new JRadioButton("JAVA"); r1.setBounds(20,20,100,20); frame.add(r1); JRadioButton r2 = new JRadioButton("ASP"); r2.setBounds(20,40,100,20); frame.add(r2); JRadioButton r3 = new JRadioButton("PHP"); r3.setBounds(20,60,100,20); frame.add(r3); ButtonGroup group = new ButtonGroup(); group.add(r1); group.add(r2); group.add(r3); frame.setVisible(true); } }
  22. 22. The JTabbedPane Class import javax.swing.*; import java.awt.*; class MyFrame { public static void main(String args[]){ JFrame frame = new JFrame("My Frame - HIST"); frame.setSize(300,300); JPanel p1 = new JPanel(); p1.setBackground(Color.YELLOW); JPanel p2 = new JPanel(); p2.setBackground(Color.GREEN); JPanel p3 = new JPanel(); p3.setBackground(Color.BLUE); JTabbedPane tpane = new JTabbedPane(); tpane.add("Java",p1); tpane.add("Asp",p2); tpane.add("Php",p3); frame.add(tpane); frame.setVisible(true); } }
  23. 23. The JTable Class import javax.swing.*; import java.awt.*; import java.awt.event.*; class MyTable { public static void main(String args[]){ JFrame frame = new JFrame("Table"); String heading[]={"Name","Course","Shift"}; Object data[][]={{"Arif","Java","M"},{"Zahid","Php","E"},{"Wasi","Asp","M"}}; JTable table = new JTable(data,heading); JScrollPane scroll = new JScrollPane(table); frame.add(scroll); frame.setSize(400,400); frame.setVisible(true); } }
  24. 24. The JInternalFrame Class import javax.swing.*; import java.awt.*; import java.awt.event.*; class MyInternalFrame { public static void main(String args[]){ JFrame frame = new JFrame("Frame"); frame.setLayout(null); JInternalFrame iframe = new JInternalFrame("Internal Frame",true,true,true,true); iframe.setSize(200,200); iframe.setVisible(true); frame.add(iframe); frame.setSize(400,400); frame.setVisible(true); } }
  25. 25. The JSpinner Class import javax.swing.*; import java.awt.*; import java.awt.event.*; class Main { public static void main(String args[]){ JFrame frame = new JFrame("Frame"); frame.setLayout(null); JSpinner spinner = new JSpinner(); spinner.setBounds(20,40,60,20); frame.add(spinner); frame.setSize(400,400); frame.setVisible(true); } }

×