akshay258

Java Swing Component (Each Separate Program)

Aug 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 32.14 KB | None | 0 0
  1. /*
  2.     Each Swing Component Used Differently, Beginner Can Understand How Swing Component Use in Java Frame
  3. */
  4. package swingoperation;
  5. import java.awt.Color;
  6. import java.awt.Font;
  7. import javax.swing.JFrame;
  8. import javax.swing.JLabel;
  9. public class SwingOperation extends JFrame
  10. {
  11.     public static void main(String[] args)
  12.     {
  13.         JFrame f = new JFrame("Private Frame");
  14.         f.setLayout(null);
  15.         f.setBounds(400, 100, 600, 500);
  16.         f.setBackground(Color.YELLOW);
  17.         Font ft = new Font("Lobster", Font.BOLD, 30);
  18.         JLabel name = new JLabel("Akshay");
  19.         name.setBounds(250, 150, 150, 40);
  20.         name.setForeground(Color.red);
  21.         name.setFont(ft);
  22.         f.add(name);
  23.         //f.setResizable(false);
  24.         f.setDefaultCloseOperation(EXIT_ON_CLOSE);
  25.         f.setVisible(true);        
  26.     }
  27. }
  28. ________________________________________________________________________________
  29.  
  30. package swingoperation;
  31. import java.awt.Font;
  32. import javax.swing.ImageIcon;
  33. import javax.swing.JButton;
  34. import javax.swing.JFrame;
  35. public class SwingOperation extends JFrame
  36. {
  37.     public SwingOperation()
  38.     {
  39.         JFrame j = new JFrame("My Frame");
  40.         j.setLayout(null);
  41.         j.setBounds(400, 100, 600, 500);
  42.         ImageIcon i = new ImageIcon("C:\\Users\\Akshay\\Downloads\\LoginUser.png");
  43.         JButton b = new JButton(i);
  44.         b.setBounds(100, 100, 50, 50);
  45.         j.add(b);
  46.         JButton submit = new JButton("Submit");
  47.         submit.setBounds(400, 100, 130, 60);
  48.         submit.setMnemonic(66);
  49.         //submit.setEnabled(false);
  50.         Font ft = new Font("Lobster", Font.BOLD, 30);
  51.         submit.setFont(ft);
  52.         System.out.println(submit.getText()); //Submit
  53.         j.add(submit);
  54.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  55.         j.setVisible(true);  
  56.     }
  57.     public static void main(String[] args)
  58.     {
  59.         SwingOperation s = new SwingOperation();
  60.     }
  61. }
  62. ________________________________________________________________________________
  63.  
  64. package swingoperation;
  65.  
  66. import javax.swing.JFrame;
  67. import javax.swing.JTextField;
  68.  
  69. public class SwingOperation extends JFrame
  70. {
  71.     public static void main(String[] args)
  72.     {
  73.         JFrame j = new JFrame("For Texting");
  74.         j.setLayout(null);
  75.         j.setBounds(400, 100, 600, 500);
  76.        
  77.         JTextField text = new JTextField();
  78.         text.setBounds(300, 100, 150, 25);
  79.         j.add(text);
  80.        
  81.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  82.         j.setVisible(true);
  83.     }
  84. }
  85. ________________________________________________________________________________
  86. Lable , TextField , Button
  87.  
  88. package swingoperation;
  89. import java.awt.Font;
  90. import java.awt.event.ActionEvent;
  91. import javax.swing.JButton;
  92. import javax.swing.JFrame;
  93. import javax.swing.JLabel;
  94. import javax.swing.JTextField;
  95. public class SwingOperation extends JFrame
  96. {
  97.     static String value;
  98.     public static void main(String[] args)
  99.     {
  100.         JFrame j = new JFrame("My Frame");
  101.         j.setLayout(null);
  102.         j.setBounds(400, 100, 600, 500);
  103.         Font f = new Font("Times New Roman", Font.PLAIN, 20);
  104.         JLabel name = new JLabel("Name : ");
  105.         name.setFont(f);
  106.         name.setBounds(100, 90, 100, 50);
  107.         j.add(name);
  108.        
  109.         JTextField text = new JTextField();
  110.         text.setBounds(200, 100, 100, 30);
  111.         j.add(text);
  112.        
  113.         JButton submit = new JButton("Submit");
  114.         submit.setBounds(200 , 180, 100, 30);
  115.         j.add(submit);
  116.        
  117.         JButton cancel = new JButton("Cancel");
  118.         cancel.setBounds(320 , 180, 100, 30);
  119.         j.add(cancel);
  120.        
  121.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  122.         j.setVisible(true);
  123.        
  124.         submit.addActionListener((ActionEvent e) ->
  125.         {
  126.                 value = text.getText();
  127.                 //JOptionPane.showMessageDialog(null, "You Entered "+value);
  128.                 submit.setEnabled(false);
  129.                 JLabel name1 = new JLabel();
  130.                 name1.setBounds(150, 300, 300, 50);
  131.                 name1.setText("You Entered : "+value);
  132.                 j.repaint();    
  133.                 j.add(name1);    
  134.         });
  135.         cancel.addActionListener((ActionEvent e) ->
  136.         {System.exit(0); });      
  137.     }
  138. }
  139. ________________________________________________________________________________
  140.  
  141. package swingoperation;
  142. import javax.swing.JFrame;
  143. import javax.swing.JTextArea;
  144. import javax.swing.text.BadLocationException;
  145. public class SwingOperation extends JFrame
  146. {
  147.     public SwingOperation() throws BadLocationException
  148.     {
  149.         JFrame j = new JFrame("Text Area");
  150.         j.setLayout(null);
  151.         j.setBounds(400, 100, 600, 600);
  152.         JTextArea a = new JTextArea("Comment\nhere...",2,10);    
  153.         a.setLineWrap(true);
  154.         a.setBounds(50, 50, 200, 100);
  155.         a.insert("Akshay", 15);
  156.         a.append(" Pawar");
  157.         a.setEditable(false);         //by default it is true
  158.         //a.setEnabled(false);          //by default it is true
  159.         //a.selectAll();
  160.         a.select(0, 15);
  161.         a.setTabSize(20);
  162.         //System.out.println(a.getLineCount());
  163.         System.out.println(a.getLineEndOffset(1));   //return ascii code of \ Escape character 27
  164.         System.out.println(a.getLineStartOffset(1));
  165.         j.add(a);        
  166.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  167.         j.setVisible(true);      
  168.     }
  169.     public static void main(String[] args) throws BadLocationException
  170.     {
  171.        SwingOperation s = new SwingOperation();
  172.     }
  173. }
  174. ________________________________________________________________________________
  175.  
  176. package swingoperation;
  177. import java.awt.Color;
  178. import java.awt.event.ActionEvent;
  179. import javax.swing.JButton;
  180. import javax.swing.JFrame;
  181. import javax.swing.JLabel;
  182. import javax.swing.JPasswordField;
  183. public class SwingOperation extends JFrame
  184. {
  185.     public static void main(String[] args)
  186.     {
  187.         JFrame j = new JFrame("Password Field");
  188.         j.getContentPane().setBackground(Color.GRAY);
  189.         j.setLayout(null);
  190.         j.setBounds(400, 100, 600, 600);
  191.         j.setBackground(Color.RED);
  192.         JLabel user = new JLabel("Password : ");
  193.         user.setBounds(100, 100, 80, 30);
  194.         j.add(user);
  195.        
  196.         JPasswordField pass = new JPasswordField();
  197.         pass.setBounds(200, 100, 200, 30);
  198.         j.add(pass);
  199.        
  200.         JButton b = new JButton("Submit");
  201.         b.setBounds(200, 170, 100, 30);
  202.         b.setBackground(Color.WHITE);
  203.         j.add(b);
  204.        
  205.         b.addActionListener((ActionEvent e) ->
  206.         {
  207.             String pswd = String.valueOf(pass.getText());
  208.             //System.out.println(pswd);
  209.             JLabel name = new JLabel(pswd);
  210.             name.setBounds(200, 250, 500, 30);
  211.             name.setText("Password is  : "+pswd);
  212.             j.repaint();
  213.             b.setEnabled(false);
  214.             j.add(name);
  215.         });
  216.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  217.         j.setVisible(true);
  218.     }    
  219. }
  220. ________________________________________________________________________________
  221.  
  222. package swingoperation;
  223.  
  224. import java.awt.event.ActionEvent;
  225. import javax.swing.JButton;
  226. import javax.swing.JCheckBox;
  227. import javax.swing.JFrame;
  228. import javax.swing.JLabel;
  229.  
  230. public class SwingOperation extends JFrame
  231. {
  232.     public static void main(String[] args)
  233.     {
  234.         JFrame j = new JFrame("Check Box");
  235.         j.setLayout(null);
  236.         j.setBounds(400, 100, 600, 600);
  237.        
  238.         JCheckBox c1 = new JCheckBox("Engineer");
  239.         JCheckBox c2 = new JCheckBox("Doctor");
  240.         JCheckBox c3 = new JCheckBox("Writer");
  241.         c1.setBounds(100, 100,80,30);
  242.         c2.setBounds(100, 130, 80, 30);
  243.         c3.setBounds(100, 160, 80, 30);
  244.         j.add(c1);
  245.         j.add(c2);
  246.         j.add(c3);
  247.        
  248.         JButton b = new JButton("Select");
  249.         b.setBounds(100, 200, 80, 30);
  250.         j.add(b);
  251.        
  252.         b.addActionListener((ActionEvent e) ->
  253.         {
  254.             if(c1.isSelected())
  255.             {
  256.                 String engg = c1.getText();
  257.                 JLabel Engg = new JLabel(engg);
  258.                 Engg.setBounds(100, 250, 100, 30);
  259.                 Engg.setText("You are "+engg);
  260.                 j.add(Engg);
  261.                 j.repaint();
  262.             }
  263.             if(c2.isSelected())
  264.             {
  265.                 String dr = c2.getText();
  266.                 JLabel doct = new JLabel(dr);
  267.                 doct.setBounds(100, 280, 100, 30);
  268.                 doct.setText("You are "+dr);
  269.                 j.add(doct);
  270.                 j.repaint();
  271.             }
  272.             if(c3.isSelected())
  273.             {
  274.                 String wri = c3.getText();
  275.                 JLabel Writer = new JLabel(wri);
  276.                 Writer.setBounds(100, 310, 100, 30);
  277.                 Writer.setText("You are "+wri);
  278.                 j.add(Writer);
  279.                 j.repaint();
  280.             }
  281.         });    
  282.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  283.         j.setVisible(true);
  284.     }
  285. }
  286. ________________________________________________________________________________
  287. package swingoperation;
  288. import java.awt.event.ActionEvent;
  289. import javax.swing.ButtonGroup;
  290. import javax.swing.JButton;
  291. import javax.swing.JFrame;
  292. import javax.swing.JLabel;
  293. import javax.swing.JRadioButton;
  294.  
  295. public class SwingOperation extends JFrame
  296. {
  297.     public static void main(String[] args)
  298.     {
  299.         JFrame j = new JFrame("Radio Button");
  300.         j.setLayout(null);
  301.         j.setBounds(400, 100, 500, 600);
  302.         JRadioButton r1 = new JRadioButton("Male");
  303.         JRadioButton r2 = new JRadioButton("Female");
  304.         r1.setBounds(100, 100, 55, 30);
  305.         r2.setBounds(160, 100, 70, 30);
  306.         ButtonGroup g = new ButtonGroup();      
  307.         g.add(r1);
  308.         g.add(r2);
  309.         j.add(r1);
  310.         j.add(r2);
  311.         JButton b = new JButton("getGender");
  312.         b.setBounds(100, 150, 100, 30);
  313.         j.add(b);
  314.         b.addActionListener((ActionEvent e) ->{    
  315.             if(r1.isSelected())
  316.             {
  317.                 String s = r1.getText();
  318.                 JLabel gend = new JLabel();
  319.                 gend.setBounds(100, 300, 100, 30);
  320.                 gend.setText("Gender : "+s);
  321.                 j.add(gend);
  322.                 j.repaint();
  323.             }
  324.             else
  325.             {
  326.                 String s = r2.getText();
  327.                 JLabel gend = new JLabel();
  328.                 gend.setBounds(100, 300, 100, 30);
  329.                 gend.setText("Gender : "+s);
  330.                 j.add(gend);
  331.                 j.repaint();
  332.             }      
  333.         });
  334.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  335.         j.setVisible(true);
  336.     }
  337. }
  338. ________________________________________________________________________________
  339.  
  340. package swingoperation;
  341.  
  342. import java.awt.event.ActionEvent;
  343. import javax.swing.JButton;
  344. import javax.swing.JComboBox;
  345. import javax.swing.JFrame;
  346. import javax.swing.JLabel;
  347. import javax.swing.JOptionPane;
  348.  
  349. public class SwingOperation extends JFrame
  350. {
  351.     public static void main(String[] args)
  352.     {
  353.         JFrame j = new JFrame("Drop Down List");
  354.         j.setLayout(null);
  355.         j.setBounds(400, 100, 500, 600);
  356.        
  357.         String[] days = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
  358.         JComboBox c = new JComboBox(days);
  359.         c.setBounds(100, 100, 100, 30);
  360.         j.add(c);
  361.        
  362.         c.addItem("Akshay");
  363.         c.addItem("Jaguar");
  364.         JButton b = new JButton("Submit");
  365.         b.setBounds(100, 150, 80, 30);
  366.         j.add(b);
  367.        
  368.         b.addActionListener((ActionEvent e) -> {
  369.             String day = (String)c.getSelectedItem();
  370.             //JOptionPane.showMessageDialog(j, ""+day);
  371.             JLabel txt = new JLabel(day);
  372.             txt.setBounds(100, 200, 150, 30);
  373.             txt.setText("you Choose : "+day);
  374.             j.add(txt);
  375.             j.repaint();
  376.             c.removeItem(day);
  377.            
  378.         });
  379.        
  380.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  381.         j.setVisible(true);
  382.     }
  383. }
  384. ________________________________________________________________________________
  385.  
  386. package swingoperation;
  387. import javax.swing.JFrame;
  388. import javax.swing.JScrollPane;
  389. import javax.swing.JTable;
  390. public class SwingOperation extends JFrame
  391. {
  392.     public SwingOperation()
  393.     {
  394.         JFrame j = new JFrame("Table in JAVA");
  395.         j.setLayout(null);
  396.         j.setBounds(400, 100, 500, 600);
  397.        
  398.         String[][] data = {
  399.             {"1","C"},
  400.             {"2","C++"},
  401.             {"3","Java"},
  402.             {"4","PHP"},
  403.             {"5","MySQL"},
  404.             {"6","JavaScript"}
  405.         };
  406.         String[] clm = {"SrNo","Language"};
  407.         JTable t = new JTable(data,clm);
  408.         t.setBounds(100, 100, 300, 100);
  409.         JScrollPane sp = new JScrollPane(t);
  410.         sp.add(t);
  411.         j.add(t);    
  412.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  413.         j.setVisible(true);
  414.     }
  415.     public static void main(String[] args)
  416.     {
  417.         SwingOperation s = new SwingOperation();
  418.     }
  419. }
  420. ________________________________________________________________________________
  421.  
  422. package swingoperation;
  423.  
  424. import javax.swing.JFrame;
  425. import javax.swing.JList;
  426.  
  427. public class SwingOperation extends JFrame
  428. {
  429.     public static void main(String[] args)
  430.     {
  431.         JFrame j = new JFrame("List");
  432.         j.setLayout(null);
  433.         j.setBounds(400, 100, 500, 600);
  434.         String[] code = {"C","C++","JAVA","PHP","HTML","CSS","JavaScript","MySQL","NnSQL","MongoDB"};
  435.         JList l = new JList(code);
  436.         l.setBounds(100, 100, 100, 200);
  437.         j.add(l);
  438.        
  439.        
  440. --------> Applicable at Popup menu
  441.  
  442. DefaultListModel m = new DefaultListModel();
  443. m.addElement("Akshay");
  444. m.addElement("Sunil");
  445. m.addElement("Pawar");
  446. l.setModel(m);              for this you display only this element
  447.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  448.         j.setVisible(true);
  449.     }
  450. }
  451. ________________________________________________________________________________
  452.  
  453. package swingoperation;
  454.  
  455.         * JOPtionPane Methods (All Method are Static)
  456.             -showInputDialog
  457.             -showConfirmDialog
  458.             -showInternalConfirmDialog
  459.             -showInternalInputDialog
  460.             -showInternalMessageDialog
  461.             -showInternalOptionDialog
  462.             -showMessageDialog
  463.          
  464.         * JoptionMessageType (int)
  465.             -ERROR_MESSAGE       (0)
  466.             -INFORMATION_MESSAGE (1)
  467.             -WARNING_MESSAGE     (2)
  468.             -QUESTION_MESSAGE    (3)
  469.             -PLAIN_MESSAGE       (-1)
  470.        
  471.         * OptionType (int)
  472.             -DEFAULT_OPTION (-1)
  473.             -CLOSE_OPTION   (-1)
  474.             -YES_NO_OPTION  (0)
  475.             -OK_OPTION      (0)
  476.             -YES_OPTION     (0)
  477.             -YES_NO_CANCEL_OPTION (1)
  478.             -NO_OPTION      (1)
  479.             -OK_CANCEL_OPTION (2)
  480.             -CANCEL_OPTION  (2)
  481.  
  482. import java.awt.HeadlessException;
  483. import javax.swing.ImageIcon;
  484. import javax.swing.JFrame;
  485. import javax.swing.JOptionPane;
  486. import javax.swing.JPanel;
  487.  
  488. public class SwingOperation extends JFrame
  489. {
  490.     public static void main(String[] args) throws HeadlessException
  491.     {
  492.         JFrame j = new JFrame("JOptionPane");
  493.         j.setBounds(400, 100, 500, 600);
  494.         String[] alpha = {"A","B","C","D","E","F","G","H","I","J","K","L","M"};
  495.         ImageIcon icon = new ImageIcon("C:\\Users\\Akshay\\Desktop\\Android.png");
  496.         //JOptionPane.showInputDialog("Enter Value");
  497.         //JOptionPane.showInputDialog(j, "Akshay");
  498.         //JOptionPane.showInputDialog("Enter Name","Akshay");   //(" Msg Type" , "Initial Value" || Initial No);
  499.         //JOptionPane.showInputDialog(j, "Akshay", "Title", JOptionPane.INFORMATION_MESSAGE, icon, alpha, 10);
  500.        
  501.         //JOptionPane.showConfirmDialog(j,"Akshay");
  502.         //JOptionPane.showConfirmDialog(j,"Akshay","Quit", JOptionPane.YES_NO_OPTION);
  503.         //JOptionPane.showConfirmDialog(j,"Akshay","Quit",JOptionPane.OK_OPTION,JOptionPane.INFORMATION_MESSAGE);
  504.         //JOptionPane.showConfirmDialog(j,"Akshay","Welcome", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, icon);
  505.        
  506.         //JPanel p = new JPanel();
  507.         //p.setLayout(null);
  508.         //p.setBounds(100, 100, 100, 80);
  509.         //j.add(p);
  510.         //JOptionPane.showInternalConfirmDialog(p, "Internal");
  511.         //JOptionPane.showInternalConfirmDialog(p, "Internal","Title", JOptionPane.OK_OPTION);
  512.         //JOptionPane.showInternalConfirmDialog(p, "Internal","Title", JOptionPane.NO_OPTION, JOptionPane.WARNING_MESSAGE, icon);
  513.        
  514.         //JOptionPane.showInternalInputDialog(p, "Akshay");
  515.         //JOptionPane.showInternalInputDialog(p, "Akshay","Quit", JOptionPane.ERROR_MESSAGE);
  516.         //JOptionPane.showInternalInputDialog(p, "Akshay","Quit", JOptionPane.INFORMATION_MESSAGE, icon, alpha, DISPOSE_ON_CLOSE);
  517.        
  518.         //JOptionPane.showInternalMessageDialog(p, "Akshay");
  519.         //JOptionPane.showInternalMessageDialog(p, "Akshay","Quit", JOptionPane.INFORMATION_MESSAGE);
  520.         //JOptionPane.showInternalMessageDialog(p, "Akshay","Title", JOptionPane.ERROR_MESSAGE, icon);
  521.         //JOptionPane.showInternalOptionDialog(p, "Akshay Pawar", "Title", JOptionPane.CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon, alpha, NORMAL);
  522.        
  523.         //JOptionPane.showMessageDialog(j, "Akshay");  OR JOptionPane.showMessageDialog(j, alpha);
  524.         //JOptionPane.showMessageDialog(j, "Akshay", "Title", JOptionPane.WARNING_MESSAGE);
  525.         //JOptionPane.showMessageDialog(j, "Akshay", "Title", JOptionPane.WARNING_MESSAGE,icon);
  526.     }
  527. }
  528. ________________________________________________________________________________
  529.  
  530. package swingoperation;
  531. import javax.swing.JFrame;
  532. import javax.swing.JScrollBar;
  533.  
  534. public class SwingOperation extends JFrame
  535. {
  536.     public static void main(String[] args)
  537.     {
  538.         JFrame j = new JFrame("Scroll Bar");
  539.         j.setLayout(null);
  540.         j.setBounds(400, 100, 500, 600);
  541.        
  542.         JScrollBar b = new JScrollBar(JScrollBar.VERTICAL,50, 25, 0, 100);
  543.             //JScrollBar(Orientation , ScrollPosition , SizeOfScroll , min , max);
  544.         b.setBounds(100, 100,15, 200);
  545.         j.add(b);
  546.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  547.         j.setVisible(true);
  548.     }
  549. }
  550. ________________________________________________________________________________
  551. package swingoperation;
  552. import javax.swing.ImageIcon;
  553. import javax.swing.JFrame;
  554. import javax.swing.JMenu;
  555. import javax.swing.JMenuBar;
  556. import javax.swing.JMenuItem;
  557. import javax.swing.JTextArea;
  558. public class SwingOperation extends JFrame
  559. {
  560.     public static void main(String[] args)
  561.     {
  562.         JFrame j = new JFrame("File Menu");
  563.         j.setLayout(null);
  564.         j.setBounds(400, 100, 515, 570);
  565.         ImageIcon icon = new ImageIcon("C:\\Users\\Akshay\\Desktop\\Android.png");
  566.        
  567.        
  568.         JMenuBar mb = new JMenuBar();
  569.         mb.setBounds(0, 0, 500, 30);
  570.        
  571.         JMenu m1 = new JMenu("File");
  572.         JMenu m2 = new JMenu("Edit");
  573.         JMenu m3 = new JMenu("View");
  574.         JMenu m4 = new JMenu("Setting");
  575.         JMenu m5 = new JMenu("Help");
  576.         m1.setMnemonic('F');
  577.         m2.setMnemonic('E');
  578.         m3.setMnemonic('V');
  579.         m4.setMnemonic('S');
  580.         m5.setMnemonic('H');
  581.         mb.add(m1);mb.add(m2);mb.add(m3);mb.add(m4);mb.add(m5);
  582.         j.add(mb);
  583.        
  584.         JMenuItem m11 = new JMenuItem("New");
  585.        
  586.         JMenuItem m12 = new JMenuItem("Open");
  587.         JMenuItem m13 = new JMenuItem("Save");
  588.         JMenuItem m14 = new JMenuItem("Save As");
  589.         JMenuItem m15 = new JMenuItem("Print");
  590.         JMenuItem m16 = new JMenuItem("Exit");
  591.         m11.setMnemonic('N');
  592.         m12.setMnemonic('O');
  593.         m13.setMnemonic('S');
  594.         m14.setMnemonic(65);
  595.         m15.setMnemonic('P');
  596.         m16.setMnemonic('E');
  597.         m1.add(m11);m1.addSeparator();
  598.         m1.add(m12);m1.addSeparator();
  599.         m1.add(m13);m1.addSeparator();
  600.         m1.add(m14);m1.addSeparator();
  601.         m1.add(m15);m1.addSeparator();
  602.         m1.add(m16);
  603.        
  604.         JMenuItem m21 = new JMenuItem("Undo");
  605.         JMenuItem m22 = new JMenuItem("Redo");
  606.         JMenuItem m23 = new JMenuItem("Cut");
  607.         JMenuItem m24 = new JMenuItem("Copy");
  608.         JMenuItem m25 = new JMenuItem("Paste");
  609.         JMenuItem m26 = new JMenuItem("Delete");
  610.         JMenuItem m27 = new JMenuItem("Find");
  611.         JMenuItem m28 = new JMenuItem("Replace");
  612.         JMenuItem m29 = new JMenuItem("SelectAll");
  613.         m21.setMnemonic('U');m22.setMnemonic('R');m23.setMnemonic('C');m24.setMnemonic('C');m25.setMnemonic('P');
  614.         m26.setMnemonic('D');m27.setMnemonic('F');m28.setMnemonic('l');m29.setMnemonic('S');
  615.         m2.add(m21);m2.addSeparator();
  616.         m2.add(m22);m2.addSeparator();
  617.         m2.add(m23);m2.addSeparator();
  618.         m2.add(m24);m2.addSeparator();
  619.         m2.add(m25);m2.addSeparator();
  620.         m2.add(m26);m2.addSeparator();
  621.         m2.add(m27);m2.addSeparator();
  622.         m2.add(m28);m2.addSeparator();
  623.         m2.add(m29);
  624.        
  625.         JMenuItem m31 = new JMenuItem("Font...");
  626.         JMenuItem m32 = new JMenuItem("Size");
  627.         JMenuItem m33 = new JMenuItem("Word Wrap");
  628.         JMenuItem m34 = new JMenuItem("Status Bar");
  629.         JMenuItem m35 = new JMenuItem("Vertical");
  630.         JMenuItem m36 = new JMenuItem("Horizontal");
  631.         m31.setMnemonic('F');m32.setMnemonic('S');m33.setMnemonic('W');
  632.         m34.setMnemonic('B');m35.setMnemonic('V');m36.setMnemonic('H');
  633.         m3.add(m31);m3.addSeparator();
  634.         m3.add(m32);m3.addSeparator();
  635.         m3.add(m33);m3.addSeparator();
  636.         m3.add(m34);m3.addSeparator();
  637.         m3.add(m35);m3.addSeparator();
  638.         m3.add(m36);
  639.        
  640.         JMenuItem m41 = new JMenuItem("Color");
  641.         JMenuItem m42 = new JMenuItem("Font Style");
  642.         JMenuItem m43 = new JMenuItem("Line No");
  643.         JMenuItem m44 = new JMenuItem("Window");
  644.         JMenuItem m45 = new JMenuItem("History");
  645.         m41.setMnemonic('C');m42.setMnemonic('F');m43.setMnemonic('L');m44.setMnemonic('W');m45.setMnemonic('H');
  646.         m4.add(m41);m4.addSeparator();
  647.         m4.add(m42);m4.addSeparator();
  648.         m4.add(m43);m4.addSeparator();
  649.         m4.add(m44);m4.addSeparator();
  650.         m4.add(m45);
  651.        
  652.         JMenuItem m51 = new JMenuItem("Dictionary");
  653.         JMenuItem m52 = new JMenuItem("Refer PDF");
  654.         JMenuItem m53 = new JMenuItem("About");
  655.         JMenuItem m54 = new JMenuItem("Visit");
  656.         m51.setMnemonic('D');m52.setMnemonic('R');m53.setMnemonic('A');m54.setMnemonic('V');
  657.         m5.add(m51);m5.addSeparator();
  658.         m5.add(m52);m5.addSeparator();
  659.         m5.add(m53);m5.addSeparator();
  660.         m5.add(m54);
  661.        
  662.         JTextArea area = new JTextArea();
  663.         area.setBounds(0,28, 500, 500);
  664.         area.setLineWrap(true);
  665.         j.add(area);
  666.        //j.setResizable(false);
  667.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  668.         j.setVisible(true);
  669.     }
  670. }
  671.  
  672. ________________________________________________________________________________
  673.  
  674. package swingoperation;
  675.  
  676. import javax.swing.ImageIcon;
  677. import javax.swing.JCheckBoxMenuItem;
  678. import javax.swing.JFrame;
  679. import javax.swing.JMenu;
  680. import javax.swing.JMenuBar;
  681. import javax.swing.JOptionPane;
  682.  
  683. public class SwingOperation extends JFrame
  684. {
  685.     public static void main(String[] args)
  686.     {
  687.         JFrame j = new JFrame("File Menu");
  688.         j.setLayout(null);
  689.         j.setBounds(400, 100, 515, 570);
  690.         ImageIcon icon = new ImageIcon("C:\\Users\\Akshay\\Desktop\\Android.png");
  691.         JMenuBar mb = new JMenuBar();
  692.         mb.setBounds(0, 0, 500, 30);
  693.         JMenu m1 = new JMenu("File");
  694.         JMenu m2 = new JMenu("Edit");
  695.         JMenu m3 = new JMenu("View");
  696.         JMenu m4 = new JMenu("Setting");
  697.         JMenu m5 = new JMenu("Help");
  698.         m1.setMnemonic('F');
  699.         m2.setMnemonic('E');
  700.         m3.setMnemonic('V');
  701.         m4.setMnemonic('S');
  702.         m5.setMnemonic('H');
  703.         mb.add(m1);mb.add(m2);mb.add(m3);mb.add(m4);mb.add(m5);
  704.         j.add(mb);
  705.         JCheckBoxMenuItem m11 = new JCheckBoxMenuItem("New      Ctrl+N");
  706.         JCheckBoxMenuItem m12 = new JCheckBoxMenuItem("Open     Ctrl+O");
  707.         JCheckBoxMenuItem m13 = new JCheckBoxMenuItem("Save     Ctrl+S");
  708.         JCheckBoxMenuItem m14 = new JCheckBoxMenuItem("Save As  Ctrl+Shift+S");
  709.         JCheckBoxMenuItem m15 = new JCheckBoxMenuItem("Print    Ctrl+P");
  710.         JCheckBoxMenuItem m16 = new JCheckBoxMenuItem("Exit     Alt+X");
  711.         m1.add(m11);m1.add(m12);m1.add(m13);m1.add(m14);m1.add(m15);m1.add(m16);
  712.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  713.         j.setVisible(true);
  714.     }
  715. }
  716. ________________________________________________________________________________
  717. package swingoperation;
  718. import java.awt.Button;
  719. import java.awt.event.ActionEvent;
  720. import java.awt.event.ActionListener;
  721. import javax.swing.JFrame;
  722. import javax.swing.JProgressBar;
  723. import javax.swing.Timer;
  724. public class SwingOperation extends JFrame
  725. {
  726.     static int prgs = 0 ;
  727.     public static void main(String[] args)
  728.     {
  729.         JFrame j = new JFrame("Progress Bar");
  730.         j.setLayout(null);
  731.         j.setBounds(400, 100, 600, 400);      
  732.         JProgressBar pb = new JProgressBar(0, 100);
  733.         pb.setStringPainted(true);
  734.         pb.setBounds(100, 100, 400, 30);    
  735.         Button b = new Button("Start");
  736.         b.setBounds(250, 150, 80, 30);
  737.         j.add(b);  
  738.         b.addActionListener((e) ->
  739.         {
  740.             b.setEnabled(false);
  741.             Timer t = new Timer(50, new ActionListener() {
  742.                 @Override
  743.                 public void actionPerformed(ActionEvent e) {
  744.                 prgs = prgs+1;
  745.                 if(prgs>100)
  746.                 {
  747.                     ((Timer)e.getSource()).stop();
  748.                 }
  749.                 pb.setValue(prgs);
  750.             }
  751.         });t.start();
  752.         });        
  753.         j.add(pb);
  754.         pb.setBorderPainted(true);
  755.         pb.setIndeterminate(false);
  756.         pb.setMaximum(100);
  757.         pb.setMinimum(0);
  758.         //pb.setString("Akshay");
  759.         //pb.setStringPainted(false);
  760.         //pb.setValue(prgs);
  761.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  762.         j.setVisible(true);
  763.     }
  764. }
  765. ________________________________________________________________________________
  766.  
  767. package swingoperation;
  768.  
  769. import java.awt.FlowLayout;
  770. import javax.swing.JFrame;
  771. import javax.swing.JTree;
  772. import javax.swing.tree.DefaultMutableTreeNode;
  773. public class SwingOperation extends JFrame
  774. {
  775.     public static void main(String[] args)
  776.     {
  777.         JFrame j = new JFrame("Tree");
  778.         j.setLayout(new FlowLayout());
  779.         j.setBounds(400, 100, 500, 500);
  780.        
  781.         DefaultMutableTreeNode tn = new DefaultMutableTreeNode("Education");
  782.         JTree t = new JTree(tn);
  783.         j.add(t);
  784.        
  785.         DefaultMutableTreeNode School = new DefaultMutableTreeNode("School");
  786.        
  787.         DefaultMutableTreeNode Engg = new DefaultMutableTreeNode("Engineering");
  788.         DefaultMutableTreeNode five = new DefaultMutableTreeNode("5th");
  789.         DefaultMutableTreeNode six = new DefaultMutableTreeNode("6th");
  790.         DefaultMutableTreeNode seven = new DefaultMutableTreeNode("7th");
  791.         DefaultMutableTreeNode eight = new DefaultMutableTreeNode("8th");
  792.         DefaultMutableTreeNode nine = new DefaultMutableTreeNode("9th");
  793.         DefaultMutableTreeNode ten = new DefaultMutableTreeNode("10th");
  794.         tn.add(School);School.add(five);School.add(six);School.add(seven);School.add(eight);School.add(nine);School.add(ten);
  795.        
  796.         DefaultMutableTreeNode Collage1 = new DefaultMutableTreeNode("Collage");
  797.         DefaultMutableTreeNode eleven = new DefaultMutableTreeNode("11th");
  798.         DefaultMutableTreeNode twelve = new DefaultMutableTreeNode("12th");
  799.        
  800.         DefaultMutableTreeNode art = new DefaultMutableTreeNode("Arts");
  801.         DefaultMutableTreeNode com = new DefaultMutableTreeNode("Commerce");
  802.         DefaultMutableTreeNode sci = new DefaultMutableTreeNode("Science");
  803.         eleven.add(art);eleven.add(com);eleven.add(sci);
  804.         DefaultMutableTreeNode art12 = new DefaultMutableTreeNode("Arts");
  805.         DefaultMutableTreeNode com12 = new DefaultMutableTreeNode("Commerce");
  806.         DefaultMutableTreeNode sci12 = new DefaultMutableTreeNode("Science");
  807.         twelve.add(art12);twelve.add(com12);twelve.add(sci12);
  808.         tn.add(Collage1);Collage1.add(eleven);Collage1.add(twelve);
  809.        
  810.         DefaultMutableTreeNode fe = new DefaultMutableTreeNode("FE");
  811.         DefaultMutableTreeNode se = new DefaultMutableTreeNode("SE");
  812.         DefaultMutableTreeNode te = new DefaultMutableTreeNode("TE");
  813.         DefaultMutableTreeNode be = new DefaultMutableTreeNode("BE");
  814.         DefaultMutableTreeNode mba = new DefaultMutableTreeNode("MBA");
  815.         tn.add(Engg);
  816.         Engg.add(fe);Engg.add(se);Engg.add(te);Engg.add(be);Engg.add(mba);
  817.        
  818.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  819.         j.setVisible(true);
  820.     }
  821. }
  822. ________________________________________________________________________________
  823. package swingoperation;
  824. import java.awt.FlowLayout;
  825. import javax.swing.JFrame;
  826. import javax.swing.JTree;
  827. import javax.swing.tree.DefaultMutableTreeNode;
  828. public class SwingOperation extends JFrame
  829. {
  830.     public static void main(String[] args)
  831.     {
  832.         JFrame j = new JFrame("Tree");
  833.         j.setLayout(new FlowLayout());
  834.         j.setBounds(400, 100, 500, 500);
  835.         String[] edu ={"A","B","C","D","E","F","G","H"};
  836.         JTree t = new JTree(edu);
  837.         j.add(t);
  838.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  839.         j.setVisible(true);
  840.     }
  841. }
  842. ________________________________________________________________________________
  843. package swingoperation;
  844. import java.awt.Color;
  845. import java.awt.FlowLayout;
  846. import javax.swing.JColorChooser;
  847. import javax.swing.JFrame;
  848.  
  849. public class SwingOperation extends JFrame
  850. {
  851.     public static void main(String[] args)
  852.     {
  853.         JFrame j = new JFrame("Color Chooser");
  854.         j.setLayout(new FlowLayout());
  855.         j.setBounds(400, 100, 500, 500);
  856.        
  857.         JColorChooser c = new JColorChooser(Color.yellow);
  858.         j.add(c);
  859.        
  860.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  861.         j.setVisible(true);
  862.     }
  863. }
  864. ________________________________________________________________________________
  865.  
  866. package swingoperation;
  867. import javax.swing.JFrame;
  868. import javax.swing.JLabel;
  869. import javax.swing.JPanel;
  870. import javax.swing.JTabbedPane;
  871. public class SwingOperation extends JFrame
  872. {
  873.     public static void main(String[] args)
  874.     {
  875.         JFrame j = new JFrame("Tabb Pane");
  876.         j.setLayout(null);
  877.         j.setBounds(400, 100, 500, 500);
  878.         JLabel name = new JLabel("Akshay Pawar");
  879.         name.setBounds(50, 50, 100, 30);      
  880.         JPanel p = new JPanel();
  881.         JTabbedPane tb = new JTabbedPane(JTabbedPane.TOP);
  882.         tb.setBounds(100, 100, 200, 200);
  883.         tb.add(p,"Main");
  884.         p.add(name);
  885.         j.add(tb);
  886.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  887.         j.setVisible(true);
  888.     }
  889. }
  890. ________________________________________________________________________________
  891. package swingoperation;
  892. import javax.swing.JFrame;
  893. import static javax.swing.JFrame.EXIT_ON_CLOSE;
  894. import javax.swing.JPanel;
  895. import javax.swing.JTabbedPane;
  896. public class SwingOperation extends JFrame
  897. {
  898.     public static void main(String[] args)
  899.     {
  900.         JFrame j = new JFrame("Tabb Pane");
  901.         j.setLayout(null);
  902.         j.setBounds(400, 100, 500, 500);
  903.         JTabbedPane tb = new JTabbedPane(JTabbedPane.TOP);
  904.         tb.setBounds(100, 100, 200, 200);
  905.         JPanel main = new JPanel();
  906.         JPanel visit = new JPanel();
  907.         JPanel help = new JPanel();
  908.         tb.add("Main",main);
  909.         tb.add("Visit",visit);
  910.         tb.add("Help",help);
  911.         j.add(tb);
  912.         j.setDefaultCloseOperation(EXIT_ON_CLOSE);
  913.         j.setVisible(true);
  914.     }
  915. }
  916. ________________________________________________________________________________
  917. */
Add Comment
Please, Sign In to add comment