Moving methods to a new class

I have a class with my GUI and methods, but i want to move my methods to their own class.
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.*;
public class Login extends JDialog implements ActionListener
ArrayList personsList;
PersonDAO pDAO;
JLabel userName, passWord;
JTextField userName1;
JPasswordField passWord1;
JButton jbnClear, jbnSubmit, jbnCancel;
String userName2, passWord2;
Container cPane;
public Login(JFrame father) {
super(father);
createGUI();
userName2  = "";
passWord2   = "";
personsList = new ArrayList();
pDAO = new PersonDAO();     
public void createGUI(){
cPane = getContentPane();
setLayout(new GridBagLayout());
//Arrange components on contentPane and set Action Listeners to each JButton
arrangeComponents();
setSize(210,170);
setTitle("Login");
setResizable(false);
setVisible(true);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
public void arrangeComponents(){
userName = new JLabel("Username");
passWord = new JLabel("Password");
userName1   = new JTextField(20);
passWord1   = new JPasswordField(20);
jbnClear  = new JButton("Clear");
jbnSubmit = new JButton("Submit");
jbnCancel = new JButton("Cancel");
GridBagConstraints gridBagConstraintsx01 = new GridBagConstraints();
gridBagConstraintsx01.gridx = 0;
gridBagConstraintsx01.gridy = 0;
gridBagConstraintsx01.insets = new Insets(5,5,5,5);
cPane.add(userName, gridBagConstraintsx01);
GridBagConstraints gridBagConstraintsx02 = new GridBagConstraints();
gridBagConstraintsx02.gridx = 1;
gridBagConstraintsx02.insets = new Insets(5,5,5,5);
gridBagConstraintsx02.gridy = 0;
gridBagConstraintsx02.gridwidth = 2;
gridBagConstraintsx02.fill = GridBagConstraints.BOTH;
cPane.add(userName1, gridBagConstraintsx02);
GridBagConstraints gridBagConstraintsx03 = new GridBagConstraints();
gridBagConstraintsx03.gridx = 0;
gridBagConstraintsx03.insets = new Insets(5,5,5,5);
gridBagConstraintsx03.gridy = 1;
cPane.add(passWord, gridBagConstraintsx03);
GridBagConstraints gridBagConstraintsx04 = new GridBagConstraints();
gridBagConstraintsx04.gridx = 1;
gridBagConstraintsx04.insets = new Insets(5,5,5,5);
gridBagConstraintsx04.gridy = 1;
gridBagConstraintsx04.gridwidth = 2;
gridBagConstraintsx04.fill = GridBagConstraints.BOTH;
cPane.add(passWord1, gridBagConstraintsx04);
GridBagConstraints gridBagConstraintsx09 = new GridBagConstraints();
gridBagConstraintsx09.gridx = 0;
gridBagConstraintsx09.gridy = 4;
gridBagConstraintsx09.insets = new Insets(5,5,5,5);
cPane.add(jbnClear, gridBagConstraintsx09);
GridBagConstraints gridBagConstraintsx10 = new GridBagConstraints();
gridBagConstraintsx10.gridx = 1;
gridBagConstraintsx10.gridy = 4;
gridBagConstraintsx10.insets = new Insets(5,5,5,5);
cPane.add(jbnSubmit, gridBagConstraintsx10);
GridBagConstraints gridBagConstraintsx11 = new GridBagConstraints();
gridBagConstraintsx11.gridx = 1;
gridBagConstraintsx11.gridy = 5;
gridBagConstraintsx11.insets = new Insets(5,5,5,5);
cPane.add(jbnCancel, gridBagConstraintsx11);
jbnClear.addActionListener(this);
jbnSubmit.addActionListener(this);
jbnCancel.addActionListener(this);
public void actionPerformed (ActionEvent e){
if (e.getSource() == jbnClear){
clear();
else if (e.getSource() == jbnSubmit){               
//Submit();
else if (e.getSource() == jbnCancel){               
cancel();
String getUsername() {
return userName1.getText();
String getPassword() {
return new String(passWord1.getPassword());
public void clear(){
userName1.setText("");
passWord1.setText("");
personsList.clear();
public void cancel(){
this.dispose();
public void Submit(){
userName2 = getUsername();
passWord2 = getPassword();
PersonInfo person = new PersonInfo(userName2, passWord2);
if(userName2.equals("") || passWord2.equals("")){
JOptionPane.showMessageDialog(null, "Please complete all fields.");
else
pDAO.loginPerson(person);
}If i do move them to their own class, in the submit method, i need to get the username. If i try
userName2 = Login.getUsername();I am told i non static method getUsername() cannot be referenced from a static context. How can i overcome this?

nick2price wrote:
well, DrLaszloJamf, thats answered it straight away. I always thought that to get an instance of another class, i had to do somthing like
Login log = new Login();But it can be done just like
private Login logI think i now understand, the top example creates a new instance of the class and passes it what is in the constructor, which would be good to use if i wanted to run the class through an event or somthing. And the second example just creates a simple instance of the class.No, that is wrong. The second line defines an instance field named log. Unless you initialize it elsewhere, this line leaves the variable with the value null. No constructor is called because of that line.
Suggestion: you have to learn to crawl before you can learn to walk. You don't even know the fundamentals of Java -- what static means, what it means to define a field. You shouldn't be touching Swing for at least another year. You need to learn the basics, first.

Similar Messages

  • Moving from com.sun.xml classes to the new xml support integrated in java

    So far, for our XML implementation, we have used the DocumentEx, ElementEx, etc. from com.sun.xml.
    We understand that xml is now supported by the java itself (javax.xml.parsers?) and we wish to update our code to use the newer API.
    Is there a simple mapping between the old DocumentEx and ElementEx and new classes in javax.xml? Can it really be simple to "get rid" of com.sun.xml?

    The combination of the:
    Oracle XML SQL Utility
    and
    Oracle XML Parser for PLSQL V2
    give you what you need.
    null

  • How do I call an Application Module method from a EntityImpl class?

    Guys and Gals,
    Using Studio Edition Version 11.1.1.3.0.
    I've got a price update form, that when submitted, takes the part numbers and prices in the form and updates the corresponding Parts' price in the Parts table. Anytime this Parts view object's ReplacementPrice attribute is changed, an application module method needs to be called which updates a whole slew of related view objects. I know you can modify view objects via associations (How do I call an Application Module method from a ViewObjectImpl class? but that's not what I'm trying to do. These AppModuleImpl methods are the hub for all price updates, as many different operations may affect related pricing (base price lists, price buckets, etc) and hence, call the updatePartPricing(key) method.
    For some reason, the below code does not call / run / activate the application module's method. The AppModuleDataControl exists and recordPartHistory(key) is registered and public. At runtime, the am.<method> code is simply ignored, and as a weird side-effect, I cannot navigate out of my current page flow.
      public void setReplacementPrice(Number value)
        setAttributeInternal(REPLACEMENTPRICE, value);
        AppModuleImpl am = (AppModuleImpl)this.getDBTransaction().findApplicationModule("AppModuleDataControl");
        Key key = new Key(new Object[]
            { getPartNumber() });
        am.recordPartHistory(key);  // AppModuleImpl method which records pricing history
        am.updatePartPricing(key); // AppModuleImpl method which updates a whole slew of related pricing tables
      }Any ideas?

    Thanks Timo.
    Turns out the code provided was correct, but the AppModuleImpl method being called was not. A dependent ViewObject wasn't returning the row I was expecting. I then tried to perform some operations on that row, which in turn ... just stopped everything, but didn't give me an error.
    It was the lack of the error that threw me off. I had never messed with calling an AppModuleImpl method from the EntityImpl so I assumed that's what was messing up.
    You are correct. It is available from the ViewRow, but I thought it better to put it in the EntityImpl. This method will be called every time the replacement cost is modified. If I didn't put it in the EntityImpl, I'd have to remember to call it every time a replacement cost changed.

  • How can I disable a method from a direved class

    I am extended TreeSet for an assigment with some new functionality.
    This new class is rbTree.
    I need to disable all of the old functions so that if a user creates a new rbTree he will only be able to use the methods defined in rbTree.
    rbTree uses some of treeSets methods using super.
    I now how to just overwrite them but I think I should let the user know those methods are unsupported, by throwing an exception. I can't throw any exceptions because most of treeSets methods don't.
    I know there is an easy way to do this, and I don't think I should just leave them blank.
    Any ideas?
    thanks in advance
    -Marc

    If you have a new class that extends TreeSet that shouldn't expose any of the TreeSet methods, don't extend TreeSet. Prefer composition over inheritance. You can use a TreeSet as a private member within your class; e.g. your new class has-a TreeSet, rather than is-a TreeSet. This way you control which functionality of the TreeSet to use, but only expose your new methods.
    Also, you should read and implement Code Conventions for the Java&#153; Programming Language - it will help you and others understand/maintain your code.
    Example:import java.util.TreeSet;
    public class RbTree
        private TreeSet set = new TreeSet();
         * only allow a specific type of object (my.pkg.MySpecialObject) to be added to the set.
        public add(MySpecialObject mso)
            set.add(mso);
        // other methods follow...
    }

  • Using main class's methods from a different class in the same file

    Hi guys. Migrating from C++, hit a few snags. Hope someone can furnish a quick word of advice here.
    1. The filename is test.java, so test is the main class. This code and the topic title speak for themselves:
    class SomeClass
         public void SomeMethod()
              System.out.println(test.SomeOperation());
    public class test
         public static void main(String args[])
              SomeClass someObject = new SomeClass();
              someObject.SomeMethod();
         public static String SomeOperation()
              return "SomeThing";
    }The code works fine. What I want to know is, is there some way to use test.SomeOperation() from SomeClass without the test.?
    2. No sense opening a second topic for this, so second question: Similarly, is there a good way to refer to System.out.println without the System.out.? Like the using keyword in C++.
    Thanks.

    pfiinit wrote:
    The code works fine. What I want to know is, is there some way to use test.SomeOperation() from SomeClass without the test.?Yes you can by using a static import, but I don't recommend it. SomeOperation is a static method of the test class, and it's best to call it that way so you know exactly what your code is doing here.
    2. No sense opening a second topic for this, so second question: Similarly, is there a good way to refer to System.out.println without the System.out.? Like the using keyword in C++.Again, you could use static imports, but again, I don't recommend it. Myself, I use Eclipse and set up its template so that when I type sop it automatically spits out System.out.println(). Most decent IDE's have this capability.
    Also, you may wish to look up Java naming conventions, since if you abide by them, it will make it easier for others to understand your code.
    Much luck and welcome to this forum!

  • Adding a new class with Creator (really simple problem i think..)

    I added a new class to my project with creator...
    class name is "CambiaNote" and there's a method called Cambia
    tabellaselezionabile is my project(package)
    I tried to run everything but It gave me an error:
    Exception Details:  org.apache.jasper.JasperException
      Error getting property 'cambia' from bean of type tabellaselezionabile.Page1I don't know, but the word cambia don't exists at all in my code... or it is not case sensitive..?
    please help, thanks

    typo: correct Paint() to paint()

  • Overwriting a method of a super class in the subclass ???

    Hi,
    can somebody tell me whether it's possible to add a new implementation of a method in the sub class which is inherited from a super class?
    I want to model my program in that way:
    1. I define a super class with some implemented methods.
    2. This class should be inherited in a sub class. One method should be used as it was implemented in the super class but another method should be overwritten in the subclass.
    I know this concept from Java but I couldn't find a way how to do it in ABAP
    Many thanks for any help!
    Best regards,
    Birgit

    hi,
    yeas you can do it,
    Subclass can re-implement  the inherited public and protected methods from superclass.Class C1 contains method METH1(public) and METH2(protected), both of which are modified and re-implemented in  its subclass C2.also you can have ur own methods in subclass.Objects are created out of both classes and the method METH1 for both objects are called.
    Output of the program demonstrates different behaviour for method METH1 of class C1 and C2.
    This demonstrates the theme.
    REPORT YSUBDEL.
    CLASS C1 DEFINITION.
      PUBLIC SECTION.
       METHODS : METH1.
      PROTECTED SECTION.
       METHODS METH2.
      ENDCLASS.
    CLASS C1 IMPLEMENTATION .
      METHOD : METH1.
       WRITE:/5 'I am meth1 in class C1'.
       CALL METHOD METH2.
      ENDMETHOD.
      METHOD : METH2.
       WRITE:/5 ' I am meth2 in class C1 '.
      ENDMETHOD.
    ENDCLASS.
    CLASS C2 DEFINITION INHERITING FROM C1.
    PUBLIC SECTION.
      METHODS : METH1 redefinition,
      meth3.
    PROTECTED SECTION.
      METHODS : METH2 redefinition.
    ENDCLASS.
    CLASS C2 IMPLEMENTATION.
    METHOD METH1.
       WRITE:/5 'I am meth1 in class C2'.
       call method meth2.
    endmethod.
      METHOD : METH2.
      WRITE:/5 ' I am meth2 in class C2 '.
    ENDMETHOD.
    METHOD : METH3.
      WRITE:/5 ' I am own method of class C2'.
    ENDMETHOD.
    endclass.
    START-OF-SELECTION.
      DATA : OREF1 TYPE REF TO C1 ,
             OREF2 TYPE REF TO C2.
      CREATE OBJECT :  OREF1 , OREF2.
      CALL METHOD : OREF1->METH1 ,
                    OREF2->METH1.
    hope it helps,
    regards

  • Calling a method from an abstract class in a seperate class

    I am trying to call the getID() method from the Chat class in the getIDs() method in the Outputter class. I would usually instantiate with a normal class but I know you cant instantiate the method when using abstract classes. I've been going over and over my theory and have just become more confused??
    Package Chatroom
    public abstract class Chat
       private String id;
       public String getID()
          return id;
       protected void setId(String s)
          id = s;
       public abstract void sendMessageToUser(String msg);
    Package Chatroom
    public class Outputter
    public String[] getIDs()
         // This is where I get confused. I know you can't instantiate the object like:
            Chat users=new Chat();
            users.getID();
    I have the two classes in the package and you need to that to be able to use a class' methods in another class.
    Please help me :(                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I have just looked over my program and realised my class names are not the most discriptive, so I have renamed them to give you a clearer picture.
    package Chatroom
    public abstract class Chatter
    private String id;
    public String getID()
    return id;
    protected void setId(String s)
    id = s;
    I am trying to slowly build a chatroom on my own. The Chatter class is a class that will be used to represent a single logged in user and the user is given an ID when he logs in through the setId and getID() methods.
    package Chatroom;
    import java.util.Vector;
    public class Broadcaster
    private Vector<Chatter> chatters = new Vector<Chatter>();
    public String[] getIDs()
    // code here
    The Broadcaster class will keep a list of all logged-in users keeps a list of all the chats representing logged-in users, which it stores in a Vector.I am trying to use the getIDs() method to return an array of Strings comprising the IDs of all logged-in users, which is why im trying to use the getID() method from the Chat class.
    I apologise if I come across as clueless, it's just I have been going through books for about 4 hours now and I have just totally lossed all my bearings

  • Calling a method in a different class?

    How do you call a method from a differnt class into the class you are working on?

    Class and method were just generic names. You should insert the names of your classes and methods.
    class OtherClass {
        public static void one() {
            System.out.println("Static method")l;
        public void two() {
            System.out.println("Non-static method");
    class MainClass {
        public static void main(String[] args) {
            OtherClass.one();
            OtherClass oc = new OtherClass();
            oc.two();
    }

  • Accessing a private variable from a public method of the same class

    can anyone please tell me how to access a private variable, declared in a private method from a public method of the same class?
    here is the code, i'm trying to get the variable int[][][] grids.
    public static int[][] generateS(boolean[][] constraints)
      private static int[][][] sudokuGrids()
        int[][][] grids; // array of arrays!
        grids = new int[][][]
        {

    Are you sure that you want to have everything static here? You're possibly throwing away all the object-oriented goodness that java has to offer.
    Anyway, it seems to me that you can't get to that variable because it is buried within a method -- think scoping rules. I think that if you want to get at that variable your program design may be under the weather and may benefit from a significant refactoring in an OOP-manner.
    If you need more specific help, then ask away, but give us more information please about what you are trying to accomplish here and how you want to do this. Good luck.
    Pete
    Edited by: petes1234 on Nov 16, 2007 7:51 PM

  • Overloaded methods in a derived class

    Hello to everyone. I'm starting to learn java with the help of "Thinking in Java". I just want something to make it clearer for me.
    Suppose I have a base class with a method, and a derived class which overloads the method:
    class Base {
      void method() {
        System.out.println("Base method");
    class Derived extends Base {
      void method() {
        System.out.println("Derived method");
    }Now, in another class somewhere I create an instance of Derived:
    Derived dv = new Derived();
    dv.method();There is no way that I can access the method from the Base class, right? The only way I can do that is through
    class Derived extends Base {
      void method() {
        super();
        System.out.println("Derived method");
    }As I said, I'm almost sure that this is correct, I just want a confirmation.

    You can change the class
    class Derived extends Base {
      void method() {
        super.method();
        System.out.println("Derived method");
      // calls Base.method()
      void baseMethod() {
        super.method();
    }

  • Setting breakpoint on any method call of a class

    Using the new (or old) debugger, is it possible to set a breakpoint that will stop on any method invocation of a class?
    I am debugging the processing of a purchase order and want the debugger to stop on any method call to CL_PO_HEADER_HANDLE_MM, which has 113 methods, so setting a breakpoint in each method is way too tedious.
    Do you know of a way to do this in one go?

    Activate Layer-Aware Debugging for class CL_PO_HEADER_HANDLE_MM, and then set breakpoint on statement CALL METHOD.
    I tried for CL_GUI_ALV_GRID, and it worked. I am on 702 release.

  • Moving ActionListener code to another class

    Hi, I got a simple GUI program like the following:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GUI extends JFrame implements ActionListener
    private JLabel oneLabel;
    private JButton hitButton;
    public GUI()
    Container c = this.getContentPane();
    c.setLayout(new FlowLayout());
    setLocation(200,20);
    oneLabel = new JLabel("");
    hitButton = new JButton("Hit Me");
    JPanel mainPanel = new JPanel(new GridLayout(2,1));
    mainPanel.add(oneLabel);
    mainPanel.add(hitButton);
    c.add(mainPanel);
    this.setSize(100,100);
    setVisible(true);
    // Action Listeners
    hitButton.addActionListener(this);
    public void actionPerformed(ActionEvent event)
    try
    if (event.getSource() == hitButton)
    oneLabel.setText("You hit me");
    catch(Exception e)
    e.printStackTrace();
    Then I got a main class that is used to access the GUI class posted above:
    public class Main
    public static void main (String[]args)
    try
    GUI G = new GUI();
    catch(Exception evt)
    evt.printStackTrace();
    What I am trying to do is move the whole actionPerformed method from the GUI class to the Main class and make it work as it was in the GUI class so that the GUI class is only responsible for generating the visual interface. Also do I need to place the addActionListener to the Main class as well? Can anyone tell me how to proceed with this?
    Thanks for your inputs.

    I have tried editing the Main class like:
    import javax.swing.*;
    import java.awt.*;
    public class Main implements ActionListener <----
    COMPILING ERROR
    public static void main (String[]args)
    try
    GUI G = new GUI();
    catch(Exception evt)
    evt.printStackTrace();
    hitButton.addActionListener(G);
    public void actionPerformed(ActionEvent event)
    try
    if (event.getSource() == hitButton)
    oneLabel.setText("You hit me");
    catch(Exception e)
    e.printStackTrace();
    It gives me a cannot find symbol error however.
    Please, I need to get this done by tonight.If you want ro Refer to G outside the try-block, you have to declare it out side
             GUI G = null;
           try{
                G = new GUI();     
      catch(Exception evt)
    evt.printStackTrace();
    if (G != null)
       hitButton.addActionListener(G);You should read the turorial about visibilty and some other chapters.
    http://java.sun.com/docs/books/tutorial/reallybigindex.html
    Greetings Michael

  • Adding componets to a new class

    I've created a new class for BidFrame Jframe, and would like to get contents from the previous method to use, or even start afresh. But when i declare an item, it still doesn't work. What am i doing wrong? The problem lies in BidFrame extend JFrame....if the code is taken out of the two brackets, everything else works. Please help
    import java.awt.*;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.lang.*;
    public class EasyAuction extends JFrame
         // JPanel for login window
                 private JPanel  biddingJPanel, oneJPanel, welcomeJPanel, registertwoaJPanel;
                 private JLabel titleJLabel, buyernameJLabel, buyerpasswordJLabel, buyerJLabel, sellernameJLabel, sellerpasswordJLabel, sellerJLabel;
                 private JButton buyerJButton, sellerJButton, registeroneJButton, registertwoJButton;
                 private JTextField buyernameJTextField, buyerpasswordJTextField, sellernameJTextField, sellerpasswordJTextField;
                 private JComboBox itemJComboBox;
                 public JPanel BidFrameJFrame;
    //Publics JPanels
    //public JPanel registertwoJFrame;
                //contentPane
                 public Container contentPane, c;
                 //no argument constructor
                 public EasyAuction()
                      createUserInterface();
                 //create and position components
                 private void createUserInterface()
                     //get contentPane
                      contentPane = getContentPane();
                      c = getContentPane();
                   //and set layout to null
                      contentPane.setLayout(null);
                      c.setLayout(null);
                   //goes to public void welcome
                      login();
                      //set properties of applications window
                      setTitle( "Easy Auction" ); // set JFrame's title bar string
                    setSize( 300, 200);   // set width and height of JFrame
                    setVisible( true );    // display JFrame on screen
                 } // end method createUserInterface
                 public void login(){
                           //setup oneJPanel
                           oneJPanel = new JPanel();
                           oneJPanel.setLayout( new FlowLayout() );
                           oneJPanel.setBounds(0,0, 300,200);
                           oneJPanel.setVisible(true);
                         // setup buyernameJLabel
                         buyernameJLabel = new JLabel();
                         buyernameJLabel.setText("Buyer Name");
                         oneJPanel.add( buyernameJLabel );
                         //setup nameJTextField
                         buyernameJTextField = new JTextField(15);
                        buyernameJTextField.
                        setEnabled(true);
                        oneJPanel.add( buyernameJTextField );
                        //setup buyerpasswordJLabel
                        buyerpasswordJLabel = new JLabel();
                        buyerpasswordJLabel.setText("Pass word  ");
                        oneJPanel.add( buyerpasswordJLabel);
                        //setup buyerpasswordJTextField
                        buyerpasswordJTextField = new JTextField(15);
                        buyerpasswordJTextField.setEnabled(true);
                        oneJPanel.add( buyerpasswordJTextField);
                        //setup buyerJLabel
                        buyerJLabel = new JLabel();
                        buyerJLabel.setText("Click on Buyer Button");
                        oneJPanel.add(buyerJLabel);
                        //setup buyerJButton
                        buyerJButton = new JButton ();
                        buyerJButton.setText("Buyer");
                        buyerJButton.setBackground( Color.YELLOW );
                        oneJPanel.add( buyerJButton );
                        buyerJButton.addActionListener(
                             new ActionListener(){
                                  public void actionPerformed( ActionEvent event )
                                       BidFrame f = new BidFrame();
                                   f.setVisible(true);
                        //setup registeroneJButton
                        registeroneJButton = new JButton ();
                        registeroneJButton.setText ("Register");
                        registeroneJButton.setBackground ( Color.ORANGE);
                        oneJPanel.add( registeroneJButton);
                        //setup sellernameJLabel
                        sellernameJLabel = new JLabel();
                        sellernameJLabel.setText("Seller Name");
                        oneJPanel.add( sellernameJLabel);
                        //setup sellernameJTextField
                        sellernameJTextField = new JTextField(15);
                        sellernameJTextField.setEnabled(true);
                        oneJPanel.add(sellernameJTextField);
                        //setup sellerpasswordJLabel
                        sellerpasswordJLabel = new JLabel();
                        sellerpasswordJLabel.setText("Pass word  ");
                        oneJPanel.add( sellerpasswordJLabel );
                        //setup sellerpasswordJTextField
                        sellerpasswordJTextField = new JTextField(15);
                        sellerpasswordJTextField.setEnabled(true);
                        oneJPanel.add( sellerpasswordJTextField );
                        //setup sellerJLabel
                        sellerJLabel = new JLabel();
                        sellerJLabel.setText("Click on Seller Button");
                        oneJPanel.add(sellerJLabel);
                        //setup sellerJButton
                        sellerJButton = new JButton ();
                        sellerJButton.setText("Seller");
                        sellerJButton.setBackground( Color.YELLOW );
                        oneJPanel.add( sellerJButton );
                        //setup registertwoJButton ();
                        registertwoJButton = new JButton ();
                        registertwoJButton.setText("Register");
                        registertwoJButton.setBackground( Color.ORANGE);
                        oneJPanel.add( registertwoJButton );
                        contentPane.add(oneJPanel);
                    return;          
              public class BidFrame extends JFrame
                      oneJPanel.setVisible(false);
                   biddingJPanel = new JPanel ();
         biddingJPanel.setLayout( new FlowLayout() );
              biddingJPanel.setBounds(0, 0, 300,200);
              biddingJPanel.setVisible(true);
              setup itemJComboBox
              itemJComboBox = new JComboBox( );
              biddingJPanel.add (itemJComboBox);
              contentPane.add(biddingJPanel);
              // main method
                 public static void main( String[] args )
                    EasyAuction application = new EasyAuction();
                    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                 } // end method main
    }//ends public class Bidding 

    Normally you would use a modal JDialog, not a JFrame, to gather additional information.
    If you need data to display in the dialog then just pass the data when you create the dialog:
    BidDialog dialog = new BidDialog(parameter1, parameter2, ....);
    dialog.setModal( true );
    dialog.setVisible(true);

  • Can we call a static method without mentioning the class name

    public class Stuff {
         public static final int MY_CONSTANT = 5;
         public static int doStuff(int x){ return (x++)*x;}
    import xcom.Stuff.*;
    import java.lang.System.out;
    class User {
       public static void main(String[] args){
       new User().go();
       void go(){out.println(doStuff(MY_CONSTANT));}
    }Will the above code compile?
    can be call a static method without mentioning the class name?

    Yes, why do it simply?
    pksingh79 wrote:
    call a static method without mentioning the class name?For a given value of   "without mentioning the class name".
        public static Object invokeStaticMethod(String className, String methodName, Object[] args) throws Exception {
            Class<?>[] types = new Class<?>[args.length];
            for(int i=0;i<args.length;++i) types[i] = args==null?Object.class:args[i].getClass();
    return Class.forName(className).getDeclaredMethod(methodName,types).invoke(null,args);

Maybe you are looking for