Code.GeekInterview.com
 
 

Java Code Base

 
Code Samples Java
 

A Simple java program to learn JTabbed


Code ResourceAuthor: srinivasaraobora  

Difficulty Level:

Published: 7th Nov 2006   Read: 5150 times  

Filed in: Java
Add Comment


 

 

Sponsored Links


 

 

A Simple java program to learn JTabbed.

 


Sample Code
  1.  
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import java.awt.event.*;
  5. class Jtabbed1 extends JFrame
  6. {
  7.         Jtabbed1()
  8.         {
  9.         Container c = getContentPane();
  10.         JTabbedPane jtp = new JTabbedPane();
  11.         jtp.setBackground(Color.black);
  12.         jtp.setForeground(Color.red);
  13.         jtp.addTab("First",new Firstpane());
  14.         jtp.addTab("Second",new Secondpane());
  15.     jtp.addTab("calculator",new Calpane());
  16.    
  17.         c.add(jtp);
  18.      }
  19. public static void main(String args[])
  20.    {
  21.         Jtabbed1 jt = new Jtabbed1();
  22.         jt.setSize(500,400);
  23.         jt.setTitle("First");
  24.         jt.setVisible(true);
  25.         jt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.     }
  27. }
  28. class Firstpane extends JPanel
  29. {
  30.         Firstpane()
  31.         {
  32.         setBackground(Color.green);
  33.                 JButton b1 = new JButton("New delhi");
  34.             b1.setBackground(Color.green);
  35.             b1.setForeground(Color.red);
  36.                 JButton b2 = new JButton("Washington");
  37.             b2.setBackground(Color.white);
  38.             b2.setForeground(Color.blue);
  39.         JButton b3 = new JButton("Tokyo");
  40.             b3.setBackground(Color.yellow);
  41.             b3.setForeground(Color.red);
  42.                 add(b1);
  43.                 add(b2);
  44.                 add(b3);
  45.         }
  46.  
  47. }
  48. class Secondpane extends JPanel
  49. {
  50.         Secondpane()
  51.         {
  52.                 JCheckBox c1,c2,c3;
  53.                 c1 = new JCheckBox("India");
  54.             setBackground(Color.black);
  55.             c1.setBackground(Color.green);
  56.             c1.setForeground(Color.red);
  57.         c2 = new JCheckBox("America");
  58.             c2.setBackground(Color.white);
  59.             c2.setForeground(Color.blue);
  60.          c3 = new JCheckBox("Japan");
  61.             c3.setBackground(Color.yellow);
  62.             c3.setForeground(Color.red);
  63.                  add(c1);
  64.                  add(c2);
  65.                  add(c3);
  66.         }
  67. }
  68. class Calpane extends JPanel implements ActionListener
  69. {
  70.        
  71.         JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,c1,c2,c3,c4,c5,c6,c7,c8;
  72.         JTextField no1;
  73.    
  74.         Calpane()
  75.         {
  76.                 setLayout(null);
  77.         setBackground(Color.red);
  78.                 no1 = new JTextField();
  79.                 no1.setBounds(150,70,180,20);
  80.         add(no1);
  81.         b1 = new JButton("1");
  82.             b1.setBackground(Color.green);
  83.             b1.setForeground(Color.red);
  84.         b1.setBounds(100,100,50,20);
  85.                 b2 = new JButton("2");
  86.             b2.setBackground(Color.white);
  87.             b2.setForeground(Color.blue);
  88.         b2.setBounds(160,100,50,20);
  89.         b3 = new JButton("3");
  90.             b3.setBackground(Color.yellow);
  91.             b3.setForeground(Color.red);
  92.         b3.setBounds(220,100,50,20);
  93.         b4 = new JButton("4");
  94.             b4.setBackground(Color.black);
  95.             b4.setForeground(Color.red);
  96.         b4.setBounds(280,100,50,20);
  97.         b5 = new JButton("5");
  98.             b5.setBackground(Color.black);
  99.             b5.setForeground(Color.blue);
  100.         b5.setBounds(100,130,50,20);
  101.         b6 = new JButton("6");
  102.             b6.setBackground(Color.yellow);
  103.             b6.setForeground(Color.green);
  104.         b6.setBounds(160,130,50,20);
  105.         b7 = new JButton("7");
  106.             b7.setBackground(Color.blue);
  107.             b7.setForeground(Color.yellow);
  108.         b7.setBounds(220,130,50,20);
  109.         b8 = new JButton("8");
  110.             b8.setBackground(Color.white);
  111.             b8.setForeground(Color.green);
  112.         b8.setBounds(280,130,50,20);
  113.         b9 = new JButton("9");
  114.             b9.setBackground(Color.red);
  115.             b9.setForeground(Color.yellow);
  116.         b9.setBounds(100,160,50,20);
  117.                 c1 = new JButton("0");
  118.             c1.setBackground(Color.white);
  119.             c1.setForeground(Color.red);
  120.         c1.setBounds(160,160,50,20);
  121.         c2 = new JButton("=");
  122.         c2.setBounds(220,160,50,20);
  123.                 c3 = new JButton("A");
  124.         c3.setBounds(280,160,50,20);
  125.                 c4 = new JButton("+");
  126.         c4.setBounds(100,190,50,20);
  127.         c5 = new JButton("-");
  128.         c5.setBounds(160,190,50,20);
  129.                 c6 = new JButton("*");
  130.         c6.setBounds(220,190,50,20);
  131.                 c7 = new JButton("/");
  132.         c7.setBounds(280,190,50,20);
  133.         c8 = new JButton("CE");
  134.         c8.setBounds(170,220,50,20);
  135.        
  136.                 add(b1);
  137.                 add(b2);
  138.                 add(b3);
  139.                 add(b4);
  140.                 add(b5);
  141.         add(b6);
  142.         add(b7);
  143.                 add(b8);
  144.                 add(b9);
  145.                 add(c1);
  146.                 add(c2);
  147.         add(c3);
  148.         add(c4);
  149.         add(c5);
  150.                 add(c6);
  151.                 add(c7);
  152.         add(c8);
  153.        
  154.         b1.addActionListener(this);
  155.                 b2.addActionListener(this);
  156.                 b3.addActionListener(this);
  157.         b4.addActionListener(this);
  158.         b5.addActionListener(this);
  159.                 b6.addActionListener(this);
  160.                 b7.addActionListener(this);
  161.         b8.addActionListener(this);
  162.         b9.addActionListener(this);
  163.                 c1.addActionListener(this);
  164.                 c2.addActionListener(this);
  165.         c3.addActionListener(this);
  166.         c4.addActionListener(this);
  167.                 c5.addActionListener(this);
  168.                 c6.addActionListener(this);
  169.         c7.addActionListener(this);
  170.         c8.addActionListener(this);
  171.                 no1.setBackground(new Color(0,45,30));
  172.         no1.setForeground(Color.red);
  173.                
  174.                
  175.         }
  176.         public void actionPerformed(ActionEvent ae)
  177.         {
  178.         String str = "";
  179.                 if(ae.getActionCommand() == "CE")
  180.                         no1.setText("");
  181.                 else
  182.                 str += ae.getActionCommand();
  183.                 no1.setText(str);
  184.                 repaint();
  185.         }
  186. }
  187.  
Copyright GeekInterview.com


Next Article: Simple Calculator


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. srinivasaraobora140703
2. iamdvr102872
3. venki_madesh35423
4. Raju20167
5. parmod kumar duhan16407
6. Kiran.jakkaraju15124
7. chowsys7786
8. ashish.cns6881
9. Venkateswara Rao6772
10. venkat_kiran5889

Active Coders

Refined Tags