Welcome to Dream.In.Code
Become a Java Expert!

Join 150,402 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 963 people online right now. Registration is fast and FREE... Join Now!




How to use Exit Button & JcomboBox

 
Reply to this topicStart new topic

How to use Exit Button & JcomboBox

suman770
2 Apr, 2008 - 09:24 PM
Post #1

New D.I.C Head
*

Joined: 6 Mar, 2008
Posts: 11


My Contributions
CODE

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
  public class welcome extends JFrame
     {
           JPanel p;
         JButton b1,b2,b3;
  public static void main(String [] args)
        {
            welcome m=new welcome();
        }
  public welcome()
    {
          p=new JPanel();
        p.setLayout(null);

   Font f1=new Font("Calibri",Font.BOLD,45);
   Font f2=new Font("Calibri",Font.BOLD,20);

   JLabel L1=new JLabel("Welcome to NIIT Student Library");

               L1.setFont(f1);

     b1=new JButton("Login");

            b1.setFont(f2);

    b2=new JButton("New User");

            b2.setFont(f2);

    b3=new JButton("Exit");

            b3.setFont(f2);

    L1.setBounds(280,170,650,90);
    b1.setBounds(320,600,120,50);
    b2.setBounds(700,600,170,50);
    b3.setBounds(950,740,150,50);

           p.add(L1);
           p.add(b1);
           p.add(b2);
           p.add(b3);

        this.getContentPane().add(p);
        this.setSize(500,500);
        this.setVisible(true);
         p.setBackground(Color.white);
            JLogin login=new JLogin();
            JLogin1 login1=new JLogin1();
            //JLogin2 login2=new JLogin2();
               b1.addActionListener(login);
              b2.addActionListener(login1);
              //b3.addActionListener(login2);

      }

      class JLogin implements ActionListener
       {
               public void actionPerformed(ActionEvent ev)
               {
                   Object ob=ev.getSource();
                   if(ob==b1)
                 {
                    Login L=new Login();
                  }
              }
         }
       class JLogin1 implements ActionListener
       {
         public void actionPerformed(ActionEvent sv)
          {
                  Object ob1=sv.getSource();
                  if(ob1==b2)
              {
                  Signup s=new Signup();
            }
          }
       }
      /*class JLogin2 implements ActionListener
      {
          public void actionPerformed(ActionEvent ae)
           {
               Object ob2=ae.getSource();
               if(ob2==b3);
                {
                    ob2.close();
                }
          }
      }*/

   }

Here "Exit" button is coming in output.But i dont know how to use this Button.i ve two more java files i ve posted here.
CODE

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Signup
       {
          public Signup()
           {
            JFrame f1=new JFrame("SignUp Form");
             JPanel p1=new JPanel();


             JLabel l1=new JLabel("Student ID");
              JLabel l2=new JLabel("First Name");
              JLabel l3=new JLabel("Last Name");
              JLabel l4=new JLabel("Password");
              JLabel l5=new JLabel("Gender");
              String []combopkg={"Male","Female"};
              JComboBox gender=new JComboBox(combopkg);

             /*JLabel l5=new JLabel("Address");
             JLabel l6=new JLabel("City");
             JLabel l7=new JLabel("Address of NIIT Center");
             JLabel l8=new JLabel("Domicile");
             JLabel l9=new JLabel("Country");
             JLabel l10=new JLabel("Pincode");*/

             JTextField tf1=new JTextField(10);
             JTextField tf2=new JTextField(10);
             JTextField tf3=new JTextField(10);
             /*JTextField tf4=new JTextField(10);
             JTextField tf5=new JTextField(10);
             JTextField tf6=new JTextField(10);
             JTextField tf7=new JTextField(10);
             JTextField tf8=new JTextField(10);
             JTextField tf9=new JTextField(10);*/
             JPasswordField pf=new JPasswordField(10);
             JButton b1=new JButton("Create My Account");

     l1.setBounds(30,15,150,80);;
     tf1.setBounds(120,38,150,29);
     l2.setBounds(30,40,100,100);
     tf2.setBounds(120,80,150,29);
     l3.setBounds(290,64,150,60);
     tf3.setBounds(370,80,150,29);
     l4.setBounds(30,95,100,80);
     pf.setBounds(120,120,150,29);
     l5.setBounds(30,125,100,80);
     b1.setBounds(400,300,170,50);

      p1.add(l1);
      p1.add(tf1);
      p1.add(l2);
      p1.add(tf2);
      p1.add(l3);
      p1.add(tf3);
      p1.add(l4);
      p1.add(pf);
      p1.add(l5);
      p1.add(gender);
      p1.add(b1);
      pf.setEchoChar('*');
      p1.setLayout(null);

     f1.getContentPane().add(p1);
     f1.setSize(500,500);
     f1.setVisible(true);
     p1.setBackground(Color.pink);
    }
}

Here JcomboBox is not working.when i delete "p1.setLayout(null)" it will work.But i want to use Both.so how can i do...plz help me...this is my project..thanks in advance.
CODE

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
   public class Login
     {
         public Login()
         {
             JFrame f1=new JFrame();
             JPanel p1=new JPanel();
             JLabel l1=new JLabel("User Name");
             JLabel l2=new JLabel("password");
     JTextField tf1=new JTextField(10);
    
     JButton b1=new JButton("Login");
     JPasswordField pf=new JPasswordField(10);
             
     l1.setBounds(350,100,650,60);
     tf1.setBounds(420,170,650,100);
     l2.setBounds(450,170,650,100);
     pf.setBounds(420,170,650,100);
     b1.setBounds(700,600,170,50);
    
     p1.add(l1);
     p1.add(tf1);
     p1.add(l2);
     p1.add(pf);
     p1.add(b1);
     pf.setEchoChar('*');
    
     f1.getContentPane().add(p1);
     f1.setSize(500,500);
     f1.setVisible(true);
     p1.setBackground(Color.pink);
    }
   }  

if any thing wrong i do plz forgive me...i am new to this forum.. smile.gif

This post has been edited by suman770: 2 Apr, 2008 - 10:46 PM
User is offlineProfile CardPM
+Quote Post

fsloke
RE: How To Use Exit Button & JcomboBox
2 Apr, 2008 - 10:55 PM
Post #2

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
When you the comboBox selected... Then you trigger the Exit function suc as System.exit(1);
User is offlineProfile CardPM
+Quote Post

suman770
RE: How To Use Exit Button & JcomboBox
2 Apr, 2008 - 11:23 PM
Post #3

New D.I.C Head
*

Joined: 6 Mar, 2008
Posts: 11


My Contributions
QUOTE(fsloke @ 2 Apr, 2008 - 11:55 PM) *

When you the comboBox selected... Then you trigger the Exit function suc as System.exit(1);

QUOTE

sorry....i did not get u.....
i have 2 questions 1->when i click on EXIT button how iT would be exit or close.Means How "Exit"
Button works.
2->when i use "p1.setlayout(null) in Signup.java" JComboBox is not Working.But when i remove the
"p1.setLayout(null) JComboBox is working.But i want to Use Both. How can i Use????

User is offlineProfile CardPM
+Quote Post

suman770
RE: How To Use Exit Button & JcomboBox
2 Apr, 2008 - 11:41 PM
Post #4

New D.I.C Head
*

Joined: 6 Mar, 2008
Posts: 11


My Contributions
QUOTE

thanx for advice..."Exit" button is working.
But how to use JComboBox with panel.setLayout(null); in my signup.java file
When i remove panel.setLayout(null) JComboBOx is working....But i want to use Both.
please help me smile.gif


This post has been edited by suman770: 3 Apr, 2008 - 01:00 AM
User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Use Exit Button & JcomboBox
3 Apr, 2008 - 05:03 AM
Post #5

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions

I the standard layout JComboBox have preferred size and that is why you see it.

In a null layout you will have to set the bounds of your gender comboBox as you do with your JLabel and JTextfield.




User is offlineProfile CardPM
+Quote Post

suman770
RE: How To Use Exit Button & JcomboBox
6 Apr, 2008 - 12:53 AM
Post #6

New D.I.C Head
*

Joined: 6 Mar, 2008
Posts: 11


My Contributions
QUOTE(pbl @ 3 Apr, 2008 - 06:03 AM) *

I the standard layout JComboBox have preferred size and that is why you see it.

In a null layout you will have to set the bounds of your gender comboBox as you do with your JLabel and JTextfield.

QUOTE

Many Many Thanx Buddy pbl...problem solves.....hats off to u....Again Can u help me a little bit
How can i implement the "BACK" & "RESET" button which is showing in my output.Means when i click on them they should work as "EXIT" button


This post has been edited by suman770: 6 Apr, 2008 - 12:54 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:14PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month