Adding toString() To an Enum Class

I have a class like the following to create named constants (similar to enums in C++):
public final class ColorConstant {   // final class!!
     private ColorConstant() {}         // private constructor!!
     public static final ColorConstant.RED = new HoldemConstant();
     public static final ColorConstant.BLUE = new HoldemConstant();
//etc
}Now, sometimes I have a handle to a ColorConstant object, and (for dubugging purposes) I want to know what it is. Problem is, If you just do "println(ColorConstant.RED)", for example, you get some garbage which is the string representatin of the object. Is there a way I can add a toString() method to the above class?
Thanks for suggestions,
John

Now, sometimes I have a handle to a ColorConstant
object, and (for dubugging purposes) I want to know
what it is. Problem is, If you just do
"println(ColorConstant.RED)", for example, you get
some garbage which is the string representatin of the
object. Is there a way I can add a toString() method
to the above class?Of course. Just name the method:
public String toString(), and have it return the appropriate string. If you want ColorConstant.RED to show "Red" for example though, you're going to have to add some state to your object, e.g. make the constructor take a String argument for the human-readable name ("Red"), and save that value as an object member.

Similar Messages

  • Adding a JPanel from one class to another Class (which extends JFrame)

    Hi everyone,
    So hopefully I go about this right, and I can figure out what I'm doing wrong here. As an exercise, I'm trying to write a Tic-Tac-Toe (TTT) game. However, in the end it will be adaptable for different variations of TTT, so it's broken up some. I have a TTTGame.java, and TTTSquareFrame.java, and some others that aren't relavent.
    So, TTTGame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              addPanel = startSimple();
              if(!addPanel.isValid())
                   System.out.println("Something's wrong");
              contents.add(addPanel);
              setSize(300, 300);
              setVisible(true);
         public JPanel startSimple()
              mainSquare = new TTTSquareFrame(sides);
              mainSquarePanel = mainSquare.createPanel(sides);
              return mainSquarePanel;
    }and TTTSquareFrame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.Misc;
    public class TTTSquareFrame
         private JPanel squarePanel;
         private JButton [] squares;
         private int square, index;
         public TTTSquareFrame()
              System.out.println("Use a constructor that passes an integer specifying the size of the square please.");
              System.exit(0);
         public TTTSquareFrame(int size)
         public JPanel createPanel(int size)
              square = (int)Math.pow(size, 2);
              squarePanel = new JPanel();
              squarePanel.setLayout(new GridLayout(3,3));
              squares = new JButton[square];
              System.out.println(MIN_SIZE.toString());
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setRolloverEnabled(false);
                   squares[i].addActionListener(bh);
                   //squares[i].setMinimumSize(MIN_SIZE);
                   squares[i].setVisible(true);
                   squarePanel.add(squares[i]);
              squarePanel.setSize(100, 100);
              squarePanel.setVisible(true);
              return squarePanel;
    }I've successfully added panels to JFrame within the same class, and this is the first time I'm modularizing the code this way. The issue is that the frame comes up blank, and I get the message "Something's wrong" and it says the addPanel is invalid. Originally, the panel creation was in the constructor for TTTSquareFrame, and I just added the mainSquare (from TTTGame class) to the content pane, when that didn't work, I tried going about it this way. Not exactly sure why I wouldn't be able to add the panel from another class, any help is greatly appreciated.
    I did try and cut out code that wasn't needed, if it's still too much let me know and I can try and whittle it down more. Thanks.

    Yea, sorry 'bout that, I just cut out the parts of the files that weren't relevant but forgot to compile it just to make sure I hadn't left any remnants of what I had removed. For whatever it's worth, I have no idea what changed, but something did and it is working now. Thanks for your help, maybe next time I'll post an actual question that doesn't somehow magically solve itself.
    EDIT: Actually, sorry, I've got the panel working now, but it's tiny. I've set the minimum size, and I've set the size of the panel, so...why won't it respond to that? It almost looks like it's being compressed into the top of the panel, but I'm not sure why.
    I've compressed the code into:
    TTTGame.java:
    import java.awt.*;
    import javax.swing.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              mainSquare = new TTTSquareFrame(sides.intValue());
              contents.add(mainSquare);
              setSize(400, 400);
              setVisible(true);
    }TTTSquareFrame.java
    import java.awt.*;
    import javax.swing.*;
    public class TTTSquareFrame extends JPanel
         private JButton [] squares;
         private int square, index;
         private final Dimension testSize = new Dimension(50, 50);
         public TTTSquareFrame(int size)
              super();
              square = (int)Math.pow(size, 2);
              super.setLayout(new GridLayout(size, size));
              squares = new JButton[square];
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setMinimumSize(testSize);
                   squares[i].setVisible(true);
                   super.add(squares[i]);
              setSize(200, 200);
              setVisible(true);
    I've made sure the buttons are smaller than the size of the panel, and the panel is smaller than the frame, so...
    Message was edited by:
    macman104

  • Enum class not supported for switch() statement in 12.4 beta?

    Hi fellow 12.4 beta testers,
    It would appear "enum class" isn't supported for switch() statements in the 12.4 beta. This compiles fine under clang and g++. Will this be fixed for the final release? This currently causes compile errors for us, since __cplusplus >= 201103L evaluates to true, so our code uses "enum class" instead of plain "enum". It looks like the C++11 standard says it should be supported:
       Switching on enum class in C++ 0x - Stack Overflow
    Many thanks,
    Jonathan.
    $ cat test.cpp
    #include <iostream>
    enum class Ternary { KnownFalse = 0, KnownTrue = 1, Unknown = 2 };
    int main( void )
       Ternary foo;
       switch ( foo ) {
          case Ternary::KnownTrue:
          case Ternary::KnownFalse:
          case Ternary::Unknown:
             std::cout << "Success\n";
    $ clang++ -std=c++11 test.cpp
    $ g++ -std=c++11 test.cpp
    $ /opt/SolarisStudio12.4-beta_mar14-solaris-x86/bin/CC -std=c++11 test.cpp
    "test.cpp", line 8: Error: Cannot use Ternary to initialize integral type.
    "test.cpp", line 8: Error: Switch selection expression must be of an integral type.
    "test.cpp", line 9: Error: An integer constant expression is required for a case label.
    "test.cpp", line 10: Error: An integer constant expression is required for a case label.
    "test.cpp", line 11: Error: An integer constant expression is required for a case label.
    5 Error(s) detected.

    Thanks for reporting this problem! I have filed bug 18499900.
    BTW, according to the C++11 standard, the code is actually not valid. Section 6.4.2, switch statement, says an implicit conversion to an integral type is required, which is not the case for for a scoped enum (one using the "class enum" syntax). This limitation was raised in the C++ Committee as an issue to be fixed, and the C++14 standard makes the code valid.
    As a workaround, or to make the code conform to C++11, you can add casts to int for the enum variable and the enumerators.
    Message was edited by: Steve_Clamage

  • Enum class

    i have written the code like the below.
    iam using Enum abstract class it is giving an error at class position.
    plz help me how to use the Enum class in our own classes.
    import java.io.*;
    import java.lang.*;
    public static final class MyBaseFrameworkEnum extends Enum {
    }

    Classes cannot extend enumerations.
    public class MyClass {
    public void myMethod(){
    private enum MyEnum {
            SOMETHING1("something"),
            SOMETHING2("something"),
            SOMETHING3("something"),
            SOMETHING4("something"),
            private String fieldName;
            MyEnum(String fieldName){
                this.fieldName=fieldName;
            public String getFieldName() {
                return fieldName;
    }or...
    public enum MyEnum {
            SOMETHING1("something"),
            SOMETHING2("something"),
            SOMETHING3("something"),
            SOMETHING4("something"),
            private String fieldName;
            MyEnum(String fieldName){
                this.fieldName=fieldName;
            public String getFieldName() {
                return fieldName;
        }Anyway, fiddle around with it.

  • [svn] 3787: Added FxTextArea, FxTextInput, and TextView class-level examples to the Component Explorer.

    Revision: 3787
    Author: [email protected]
    Date: 2008-10-21 12:16:28 -0700 (Tue, 21 Oct 2008)
    Log Message:
    Added FxTextArea, FxTextInput, and TextView class-level examples to the Component Explorer.
    Modified Paths:
    flex/sdk/trunk/samples/explorer/explorer.xml

    One workaround is to turn off automation:
    File-->Options, Advanced tab, General Section, uncheck "Enable Automation Events"
    However, you will loose the ability to configure callouts, and all of the commands in the Process Engineering tab.
    Another workaround is to change the loop number of the shape you are editing before changing its type. Then change the loop number back to the correct loop number.
    This is another example of the pernicious philosophy of trying to help the user do what the programmers think the user is trying to do that started in Excel 2000 (where you can no longer tell excel that you want a scatter plot - it will force the plot
    to be a line plot under certain circumstances).
    I suppose another option would be to modify the master and swap the text and subtype shapes in the indicator to use the subtype property for the loop number and then use the text for the instrument type. I guess this is what MS was trying to implement, but
    didn't explain it well enough to their programmers.

  • [svn:osmf:] 14028: Adding missing TestVerticalAlign and TestHorizontalAlign classes.

    Revision: 14028
    Revision: 14028
    Author:   [email protected]
    Date:     2010-02-08 01:42:06 -0800 (Mon, 08 Feb 2010)
    Log Message:
    Adding missing TestVerticalAlign and TestHorizontalAlign classes.
    Added Paths:
        osmf/trunk/framework/OSMFTest/org/osmf/layout/TestHorizontalAlign.as
        osmf/trunk/framework/OSMFTest/org/osmf/layout/TestVerticalAlign.as

    Sorry about that. I am not exactly sure where the problem is, but I know it takes place after I put the <nav> in (in the html portion). If I understand what I am learning, the CSS at the top will structure my html code so I would have thought the CSS tageting my nav would be the focus. Maybe it is a different section though.
    CSS part:
    nav p {
    font-size: 90%;
    color: #FFC;
    text-align: right;
    font-weight: bold;
    background-color: #090;
    padding-top: 5px;
    padding-right: 20px;
    padding-bottom: 5px;
    border-top-width: 2px;
    border-top-style: solid;
    border-top-color: #060;
    HTML part: (bold italic is the part I added)
    <body>
    <div class="container">
      <div id="apDiv1"><img src="Lessons/images/butterfly-ovr.png" width="170" height="158" alt="GreenStart Logo"></div>
      <header></header>
      <nav>
        <p>Home | About Us | Contact Us</p>
      </nav>
      <div class="sidebar1">
        <ul class="nav">
          <li><a href="#">Green News</a></li>
          <li><a href="#">Green Products</a></li>
          <li><a href="#">Green Events</a></li>
          <li><a href="#">Green Travel</a></li>
          <li><a href="#">Green Tips</a></li>
        </ul>

  • Accessing enum members from enum Class literal

    I'm using enums to provide a configuration framework. They work well, but I've hit a problem. This may be a bad use-case or just end up as a limitation of the enum support.
    In a nutshell I want to return the enum container type from a method and allow clients to access the members of that enum directly. For example:
    interface Widget
      Class<?> getColours();
    class MyWidget implements Widget
      enum COLOUR { RED, GREEN, BLUE };
      public Class<COLOUR> getColours() { return COLOUR.class;}
    // client
    MyWidget w = new MyWidget();
    w.setColour( w.getColours().BLUE ); // compile error!Of course, this gives a compile error as getColours() returned a class literal which doesn't have the field BLUE. However it seems like there should be a way to do this as all the information is there (the class literal has the necessary type information and can see the type is an enum). I've see Class#getEnumConstants() but this defeats the point by using an id or key to the enum rather than the enum member. Perhaps something like Class#asEnum():
    COLOUR b = w.getColours().asEnum().BLUE;I currently solve this by using naming conventions. Each widget implementer is required (by the framework) to provide an enum with the name 'COLOUR' that provides the colours it supports. However I'd prefer to have this on the interface to remind implementers to expose these configuration options.
    One other workaround is to create a custom container that holds a reference to each enum field ... but its not pretty:
    class MyWidget implements Widget
      public static class COLOURS
        private static COLOURS instance = new COLOURS();
        private COLOURS() {}
        public COLOUR RED = COLOR.RED;
        public COLOUR BLUE = COLOR.BLUE;   
        public COLOUR GREE = COLOR.GREEN;
        enum COLOUR { RED, GREEN, BLUE };
      public COLOURS getColours() { return COLOURS.instance;}
    // client
    MyWidget w = new MyWidget();
    w.setColour( w.getColours().BLUE ); // OKHas anyone hit this before and found a better solution? Is there something I've missed? If not does this seem like a reasonable request for improvement?

    I suspect you're better off using the static values() or valueOf(String) methods on the enum you create.
    So you could do
    Colour c = Colour.valueOf("BLUE");or even
    Color particularColour = null;
    for(Colour c : Colour.values()) {
        if (c.isApplicable(someCriteria)) {
            particularColour = c;
            break;
    }assuming you created a method isApplicable in the Colour enum. All I'm trying to suggest in this latter example is that selection of an enum value might be better delegated to the enum than performed by the caller.

  • Passing general "enum" "class" "thing" :-(

    What I'm trying to do is pass a general enum to a method, like this:
    public void parseEnum(enum toParse)
         for(enum blah : enum.values())
              System.out.println(blah);
    }or whatever (don't care if the stuff inside the method works right now, just threw up an example). I can't do this. Why not? Is there some kind of way I can manage to do this?
    The problem is that I have a whole bunch of enums structured like this:
    enum ListOfElementIds
         ID_ONE( "ThingOne" ),
         ID_TWO( "ThingTwo" ),
         ETC( "ThingThreeOhNoes" ),
         AND_ETC( "ThingFourIsTooMany" );
         private String elementId;
         String getElementId()
              return elementId;
         ListOfElementIds( String elementId )
              this.elementId = elementId;
    }and I'd LIKE to, via a single method, cycle through each of the "values" (ID_ONE would be a value) of any enum I give as a parameter of the method.
    If I'm not explaining this well, please let me know how I can elaborate so as to make my problem as lucid as possible :-P
    (I'm a QA tester writing selenium tests and all the developers that I usually bug about this stuff are OoO :-( )

    import java.lang.reflect.*;
    enum ExampleEnum {HELLO, WORLD};
    public class EnumExample {
        public void iterate(Class<? extends Enum> cls) {
            try {
                Method m = cls.getMethod("values");
                Enum[] values = (Enum[]) m.invoke(null);
                for(Enum e : values) {
                    process(e);
            } catch (NoSuchMethodException exc) {
                exc.printStackTrace();
            } catch (IllegalAccessException exc) {
                exc.printStackTrace();
            } catch (InvocationTargetException exc) {
                exc.printStackTrace();
        public void process(Enum e) {
            System.out.println(e);
        public static void main(String[] args) {
            new EnumExample().iterate(ExampleEnum.class);
    }The values method is static.

  • ToString() of the Object class. Guide please

    Hiya,
    I need to ask a question please.
    I havent understood the exact meaning of the toString() defined
    in the Object class?
    When and where do we need to override this?
    How can I use this inherited method and see the output
    How can I use this method,now overidden and see the output.
    Can some please send in a small code...
    Regds

    "String Representation" doesn't sound like a widget to
    me... I haven't tried it, though. Can you provide some
    code please, showing how I could use the mechanism you
    mentioned?You know.... Widgets!import java.awt.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        MyObject[] myData = {new MyObject("Hello",1),new MyObject("Hi",27)};
        JList jl = new JList(myData);
        jl.setCellRenderer(new Widget());
        content.add(jl, BorderLayout.CENTER);
        setSize(300, 300);
        setVisible(true);
      public static void main(String[] arghs) { new Test3(); }
    class Widget extends DefaultListCellRenderer {
      public Component getListCellRendererComponent(JList list, Object value,int index,
                                                    boolean selected,boolean focus) {
        JLabel jl = (JLabel)super.getListCellRendererComponent(list,
            value,index,selected,focus);
        jl.setText("("+jl.getText()+")");
        return jl;
    class MyObject extends Object {
      String name;
      int num;
      public MyObject(String name, int num) {
        this.name=name;
        this.num=num;
      public String toString() { return name+"-"+num; }
    }

  • Adding toString method

    Is there any way to programmatically add a toString method() to the
    generated classes? I have a number of objects that will be used to
    populate pick lists or put in other swing components. They will only
    display correctly if toString() is defined. I was thinking along the
    lines of specifying the fields that would be returned from toString(). In
    the custom.properites format, something like:
    com.foo.jdo.Person.tostring: forename,surname
    Doug

    I looked at the docs mentioned and at the javadocs for FieldMapping,
    ReverseCustomizer, etc. It looks quite complex, I'm not sure where to
    start. Can you quickly summarize what steps need to be taken? For
    example, for my class Person:
    public class Person {
    private Date birthDate;
    private String birthPlace;
    private EyeColor eyeColor;
    private String forename;
    private String surname
    Say I want to add a toString() method that returns
    forename + surname. I don't want to add any new fields, just the method.
    Marc Prud'hommeaux wrote:
    Doug-
    Do you mean in the reverse mapping process? There isn't any built-in way
    to do this, but it is quite simple to implement your own implementation
    of kodo.jdbc.meta.ReverseCustomizer, which will allow you to add
    something like this to the generated code.
    For more details on this, see:
    http://docs.solarmetric.com/manual.html#ref_guide_pc_reverse_custom
    In article <c372g8$bhg$[email protected]>, Doug Emerald wrote:
    Is there any way to programmatically add a toString method() to the
    generated classes? I have a number of objects that will be used to
    populate pick lists or put in other swing components. They will only
    display correctly if toString() is defined. I was thinking along the
    lines of specifying the fields that would be returned from toString(). In
    the custom.properites format, something like:
    com.foo.jdo.Person.tostring: forename,surname
    Doug
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Adding a variable to a class causes a WinRT originate error.

    I have a Clock class which causes my game to crash after I add the following line
    public:
    int FrameTimeTicks; // this line will cause the crash
    the error message reads:
    First-chance exception at 0x74B24598 (KernelBase.dll) in HH.exe: 0x40080201: WinRT originate error (parameters: 0x80000013, 0x0000001D, 0x02C3D5E0).
    First-chance exception at 0x74B24598 in HH.exe: Microsoft C++ exception: Platform::ObjectDisposedException ^ at memory location 0x02C3DA80. HRESULT:0x80000013 The object has been closed.
    WinRT information: The object has been closed.
    The program '[8200] HH.exe' has exited with code 0 (0x0).
    This is completely meaningless to me. It's a strange problem.
    Edit: When i step through the program, a breakpoint on the first line of MainPage() isn't reached before the exception is thrown. I can put a breakpoint in Clock constructor which looks like this:
    Clock::Clock()
    QueryPerformanceFrequency(&frequency);
    QueryPerformanceCounter(&pCountAppStart);
    //FrameTimeTicks = {};
    And it will be hit, when i step through from there, execution reaches the end of Clock(), goes to MainPage() open brace, but before it hits the first line I get "Source not available - Source information is missing from the debug information for this
    module ..."
    So has MainPage been disposed ?
    Here is the Clock.h file:
    #pragma once
    #include <Windows.h>
    #include <map>
    #include "Debug.h"
    using namespace std;
    using namespace Platform;
    using namespace Platform::Collections;
    class Clock
    public:
    Clock();
    int64 MarkIn();
    int64 MarkOut();
    //int FrameTimeTicks; // can't add these
    //int FrameTimeMS = 0;
    private:
    LARGE_INTEGER frequency = {};
    LARGE_INTEGER pCountAppStart = {};
    LARGE_INTEGER pCountStt = {};
    LARGE_INTEGER pCountEnd = {};
    //int frameTimeTicks; // can't add these either
    //int frameTimeMS;

    So I think I have found the problem here, and I came to a fix by using Analyze > Run code analysis on solution. Something I've never used before. When i ran it, it gave me 3 issues, one of the issues was that I was using a byte* to pixel data after a
    failed call to
    IBufferByteAccess->Buffer(&pixels);
    I don't know why the call is failing as I call it immediately after creating the WriteableBitmap, and then later in ClearBitmap. Also, the call result never returns a failure. But, nevertheless, by checking for the HRESULT and returning NULL if it fails,
    then checking for NULL in the calling functions. The issue seems to have been resolved and I can add variables to my clock class.
    I guess something weird was happening with memory.

  • 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);

  • Adding values into a driver class

    I have this code:
    public PetStay(Pet p, String oName, String oNric, GregorianCalendar ciDate, int ciId)
    this.Pet=p;
    this.ownerName=oName;
    this.ownerNric=oNric;
    this.checkInDate=ciDate;
    this.checkInId=ciId;
    this.service2=new DefleaingService();
    this.service1=new BathingService(ciDate);
    When i am writing the driver class, how do I enter values for the GregorianCalender attribute?

    BathingService bath=new BathingService(ciDate);
    GregorianCalendar ciDate=new GregorianCalendar(checkInDate);
    double bathe=bath.getAmountPayable();
    when i tried to compile it said cannot find symbol(its in a driver class)
    can someone help me fix these errors?

  • Adding Frames to a Java Class

    Hey!
    I have a class and was wondering how(if possible) is it to add a frame to the progeam...So that I can exectue the app not from fronsole but as a window(frame?)
    Do I need to Create another class, or modify the original Tester Class? Is it possible to take a working class(its simple, nothing too complicated), with some defined methods, and add them to a frame?
    Thanks!

    Thanks for your reply.
    Ill give you more insight.
    See, the program displays a drawing made by invoking a setChar Method(which is defined in a separate class). Also it shows the same drawing but with predefined replaced characters invoking a Replace method(aalready defined in another class I created), and a last drawwing which removes characters from respective coordinates.
    The Frame I would like to create I believe should be as simple as possible. I would like to just add a frame to the whole app. Maybe add three buttons, each representing one of the methods mentioned before, and another "Space" within the frame that shows teh output(in this case the drawing) After clicking on the respective choice.
    I have the code of both the tester and the class but I dont know if it is necessary right now. If it is Ill send it in my next post.
    Thanks and any insight will be appreciated!

  • Adding operations on SourceDataLine implemented Class

    i am about to finish my reusable Simple Player class, but i forgot to add the operation
    setMicroSecondPosition( similar to Clip )
    i couldn't find anyway on how to implement such operation... i wonder why there's a getMicroSecondPosition method but it doesn't have a setter method.
    What i mean is the SourceDataLine.
    i am about to browse the source code of Clip class and examine its implementation, but before i proceed, i need your advise or any alternative way( simple way ) to have this operation... would you experts guide me what class should i use to come-up with that operation?
    Articles, examples, algorithms or any advise would be appreciated.

    Why are you not using the Clip class for this? I believe the clip class loads the entire file into memory. For a lot of uses, especially players that may load large files, that's less than ideal.
    forgot to add the operation
    setMicroSecondPosition( similar to Clip )You can write this functionality, but it isn't going to be built-in. Clip has it built-in because clip has random access to all points in the file, because, it has the entire file loaded. SourceDataLine doesn't have anything pre-loaded. It gets data, presumably from an AudioInputStream, and it plays it.
    The easiest way to implement setMicroSecondPosition on a SourceDataLine that is reading data from an AudioInputStream would be to reset the stream to the beginning of the file, and then call "skip" on the stream to go back forward. You can also use the mark command to set the reset position to the start of the file, but that may not work in all cases and cause an IOException (you could just catch that and restart the stream manually in that case, though).

Maybe you are looking for

  • Acrobat 10 data1.cab corrupt

    Adobe Acrobat ver. 10.0.3 Windows 7 Enterprise (64-bit) OS English I have been trying to update to Acrobat 10.1, but the update keeps failing with the following message: Error 1334. The file 'ia32.ppi' cannot be installed because the file cannot be f

  • Freight amount during GRN

    Dear Gurus, Material's order unit and pricing unit is in PC and freight amount needs to be in Rs/KG(on the unit of KG), as the vendor will take the freight as per the actual weight of the material, same will come to know during weighing at the time o

  • Multiple facts in EIS

    I have a customer with a datawarehouse solution with a number of star schemas. However in the EIS documentation the recommendation/requirement is to use only one fact table. I want to build an Essbase cube based on two different facts. To merge the t

  • ITunes system tray icon goes missing after Windows Explore Crash!

    When windows explore crashes the iTunes system tray icon goes missing. Can you please make it so the iTunes icon will still remain in the windows system tray after a windows explore crash? Other software I use icons remain in the system tray after a

  • Where can I find more informatio​n, tutorials, or examples using the toolkit NXT for labview?

    I have read all the PDF's of the page http://zone.ni.com/devzone/cda/tut/p/id/4435 : LabVIEW_Toolkit_for_LMS_NXT_Getting_Started_Guide How_To_Create_NXT_Blocks_with_NI_LabVIEW LabVIEW_for_NXT_Advanced_Programming_Guide but I want to know if you know