Display two buttons

Hello

I try to display two buttons. I wrote the following code:

import java.awt.*. *;

Javax.swing import. *;

public class Gui32B {}

Public Shared Sub main (String [] args) {}

JFrame frame = new JFrame ();

frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

frame.setSize (new size (300, 100));

frame.setTitle ("a frame");

frame.setLayout (new FlowLayout());

JButton button1 = new JButton ();

Button1.SetText ("I'm a button");

Button1.setbackground (Color.Blue);

Frame.Add (button1);

JButton button2 = new JButton ();

Button1.SetText ("Click Me");

Button1.setbackground (Color.Red);

Frame.Add (button2);

frame.setVisible (true);

}

}

His poster the 2 buttons, but there is no text on the first button. The 2nd button also has a transparent top rectangle. Some body please correct my program. I used the border and the flow of page layouts.

Zulfi.

Hello

I am able to run the code:

import java.awt.*. *;

Javax.swing import. *;

creation of 2 buttons

no visible Button2

public class Gui3 {}

Public Shared Sub main (String [] args) {}

JFrame frame = new JFrame ();

frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

frame.setSize (new size (300, 100));

frame.setTitle ("a frame");

frame.setLayout (new FlowLayout());

JButton button1 = new JButton ();

Button1.SetText ("I m a button");

Button1.setbackground (Color.Blue);

frame.getContentPane () .add (button1);

JButton button2 = new JButton ();

Button2.SetText ("Click me");

Button2.setbackground (Color.Red);

frame.getContentPane () .add (button2);

Frame.Pack ();

frame.setVisible (true);

}

}

Thanks for your link.

Zulfi.

Tags: Java

Similar Questions

  • Two button dialogue - fire once

    I have an application where I need to get a lot of responses from the user through two button dialog boxes. I need to feel the change of State of a locked DI and when he goes UP, display a dialog of two buttons for the user to interact. As this happens inside a while loop 100ms, I need to remove the dialog box after the user selection is made. Otherwise the pop up will happen several times as the DI is locked in a HIGH State.

    While I was able to get the feature with a registry change (see attachment to LV2009), I was wondering if there was a better way to do this kind of "once-only-messages?

    Thank you

    It is not a good idea to change the status of the digital input which is "read only".

    The final VI with the required change is as below:

  • Formatting text in "function of two button dialog box."

    With monitors high resolution, the text in the Panel that displays the function of two dialog button is often small and difficult to read (at least for these old eyes).  Is it possible to format this text?

    Roy

    You can make your own.

    Make a simple Subvi with two buttons and a text indicator. Make windows style 'dialogue' appearance and add some logic (for example an event structure) to flip the button which was pressed.

  • How to add the full value of two buttons?

    How to add the full value of two buttons (any key) VI and display it in the output text box? I am attaching a sample program, but I know that his evil... Help, please

    Try this

  • Two buttons

    I have two buttons.

    -first button on the left of the screen

    -second button to the right of the screen

    I try to do it like that, but it doesn't work)

    HorizontalFieldManager titleHFM = new HorizontalFieldManager (HorizontalFieldManager.FIELD_HCENTER);
    HorizontalFieldManager leftHFM = new HorizontalFieldManager (HorizontalFieldManager.FIELD_LEFT);
    leftHFM.add (new ButtonField ("Left"));
    HorizontalFieldManager rightHFM = new HorizontalFieldManager (HorizontalFieldManager.FIELD_RIGHT);
    rightHFM.add (new ButtonField ("Right", ButtonField.RIGHT));
    titleHFM.add (leftHFM);
    titleHFM.add (rightHFM);
    Add (titleHFM);

    Hello

    You can get this in overridng sublayout the title of Manager and not need to take the separate handler for each button.

    Try like this,

    HorizontalFieldManager titleHFM = new HorizontalFieldManager (HorizontalFieldManager.FIELD_HCENTER)
    {
    protected void sublayout (int maxWidth, maxHeight int)
    {
    setPositionChild (getField (0), 0, 0);
    layoutChild (getField (0), getField (0) .getPreferredWidth (), getField (0) .getPreferredHeight ());
                    
    setPositionChild (getField (1), Display.getWidth () - getField (1) .getPreferredWidth (), 0);
    layoutChild (getField (1), getField (1) .getPreferredWidth (), getField (1) .getPreferredHeight ());
                    
    setExtent (maxWidth, maxHeight);
    }
    };

    titleHFM.add (new ButtonField ("Left"));
    titleHFM.addnew ButtonField ("Right");

    Kind regards

    Lakshman K

  • Using two buttons market timer / stop, need help please.

    Hey everybody.

    I am stil working on my project, and now I'm trying to implement a timer using two buttons market / stop. Everything I do now is when you press start the stopwatch starts and when you press stop I want the timer to stop and display the time.

    Whats happening is when I press start, the timer starts, but when stop is pressed the timer displays a value of say 12 seconds, a second more later I press stop again a value of 14secs arise and it stops at 14.  Now, whenever I press on start it will start at 14 and repeat this process.

    So I think that somewhere, I did not put my right timer.

    Could someone say somethings that I should change in my code.

    They are declared at the top:

    static public boolean status=false;
    static public int count=0;
    static public Timer timer;
    

    Here is my code:

    ButtonField start = new ButtonField("Start",ButtonField.USE_ALL_WIDTH|                          ButtonField.FIELD_HCENTER|ButtonField.USE_ALL_HEIGHT);                          start.setChangeListener(new Listener1());add(start);
    
    ButtonField stop = new ButtonField("Stop",ButtonField.USE_ALL_WIDTH|                            ButtonField.FIELD_HCENTER|ButtonField.USE_ALL_HEIGHT);                            stop.setChangeListener(new Listener2());                          add(stop);          
    
                public class Listener2 implements FieldChangeListener            {            public void fieldChanged(Field field, int context)             {            ButtonField btn = (ButtonField) field;            Status.show("Timer is at" + Integer.toString(count));            status = false;            timer.cancel();            }            }
    
                public class Listener1 implements FieldChangeListener            {            public void fieldChanged(Field field, int context)             {            ButtonField btn = (ButtonField) field;            Status.show("Timer started");            status = true;                try                {                                                timer = new Timer();                                        timer.scheduleAtFixedRate(new StartEvent(),1,1000);                }                catch(Exception e)                {                //do nothing                }            }
    
        private class StartEvent extends TimerTask    {    public void run()       {        if(status = true)              {              count++;                        }        else            timer.cancel();//        count=0;    }    }    }
    

    any help is appreciated

    Thank you guys

    Probably best to follow just a matter of a Thread.  So next time, you can start a new Thread with a new question.  However, you should also search the forum before asking questions, that your two supplementary questions have been answered in other posts on this forum.

    Concerning your problem to press the stop and get another moment, I think that you must have application logic that disables the stop button once pressed, until you press the Start button.  For example, you could do by assigning to the time of departure - 1 in the Stop button, and then, when you press the Stop button, he can check the start time and displays a message saying "Timer not started" If the start time is - 1.  There are a number of other ways to do this, I described this method because it is easy to explain.  It is not really how I'd do.

    The best way to set the buttons next, is to add then to a HorizontalFieldManager, then add the HorizontalFieldManager to your screen.

    To stop the button displays the menu, you must set it with the style CONSUME_CLICK, for example:

    ButtonField stopButton = new ButtonField ("Stop", ButtonField.CONSUME_CLICK);

  • Displays a button on the quiz results slide

    Use 6 Captivate, I show a "print" on the quiz results slide key only if the user passes the quiz. I tried setting the action in the Quiz > success or failure of the settings to display the button (with a tip action) passed the test but still no luck. On the results for the "print" key slide, I disabled the 'Visible output. Any ideas?

    You can download a complete list with the system variables of: System variables in Captivate 8 - Captivate blog

    The variable system quiz, you will need to use a conditional action is cpQuizInfoPassFail, which is a Boolean value, cannot have two values 1 or 0 (failure) (past).

    Use the event to enter the Score slide to trigger a conditional, tip action

    IF cpQuizInfoPassFail is equal to 1

    See the Bt_Print

    Continue

    ON THE OTHER

    Continue

  • two buttons with single function

    I want to create two buttons for single function and a single button for a function. For example, I click on button1, the display shows "clicked1".

    If I clicked on button2, the display shows "clicked2". If I click on button1, and then click button2, it will show that "the two buttons are clicked. However, it does not work in two buttons with single function. What is the problem? Here's the code.

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    var button1:MovieClip = new Button1();

    Button1.x = 200;

    Button1.y = 200;

    addChild (button1);

    var button2:MovieClip = new Button2();

    Button2.x = 300;

    Button2.y = 250;

    addChild (button2);

    Button1.addEventListener (MouseEvent.CLICK, onClick);

    Button2.addEventListener (MouseEvent.CLICK, onClick2);

    var isClicked:Boolean;

    var isClicked1:Boolean;

    function onClick(evt:MouseEvent):void {}

    isClicked = true;

    trace ("clicked1");

    }

    function onClick2(evt:MouseEvent):void {}

    isClicked1 = true;

    trace ("clicked2");

    }

    If (isClicked & & isClicked1) {}

    trace ("two buttons are clicked");

    }

    Copy the following code

    If (isClicked & isClicked1) {}

    trace ("two buttons are clicked");

    }

    should run WHEN you click on your buttons.  That is to say, place it in a function and call that function when you click on your buttons and after that your Boolean values are updated.  (probably then want to reset these Boolean values in the called function).

  • How to position the two buttons at the top of the div inside a container div element?

    Hello!

    Good news...

    I created my very first thumbnail slider for my site that actually works!

    Bad news...

    The buttons that allow to scroll the div element, which is encapsulated in a container of Center, are are more placed on top of the div.

    Here's the html code:

    < div id = "centerContainer" >

    < div id = "aemcSlider" >

    < ul >

    < li >

    "< a class ="aemcPkgBut"href =" "target =" "alt ="AEMC Packaging"title ="AEMC Packaging"> < / has >

    < /li >

    < li >

    "< a class ="aemcGroundFlexBut"href =" "target =" "alt ="GroundFlexAd"title ="GroundFlex Ad"> < / a >

    < /li >

    < li >

    "< a class ="aemcClampBut"href =" "target =" "alt ="Clamp-On Announces"title ="Clamp-On Announces"> < / has >

    < /li >

    < li >

    "< a class ="aemcMetrixBut"href =" "target =" "alt ="Metrix Announces"title ="Metrix Announces"> < / has >

    < /li >

    < /ul >

    < / div >

    < div id = "leftBut" >

    "< a class ="arrowLeft"href =" "target =" "alt ="Left"title ="Left"> < /a >

    < / div >

    < div id = "rightBut" >

    "< a class ="arrowRight"href =" "target =" "alt ="Right"title ="Right"> < /a >

    < / div >

    < / div >

    Here's the CSS:

    Key container:

    #centerContainer

    {width: 800px; margin: 0 auto; background-color: #0e210e; position: relative}

    Div element:

    #aemcSlider

    {

    text-align: center;

    list-style: none;

    Width: 450px;

    height: 114px;

    margin: 0 auto;

    padding-top: 0px;

    padding-right: 0px;

    padding-bottom: 0px;

    padding-left: 0px;

    top: 67px;

    position: relative;

    overflow: hidden;

    }

    #aemcSlider a {margin right:-12px ;}}

    Left and right buttons:

    a.arrowLeft

    {

    Width: 29px;

    height: 96px;

    float: left;

    position: absolute;

    margin: 0 auto;

    display: block;

    background-image: url (.. / Images/arrowLeft.png);

    background-repeat: no-repeat;

    left: 311px;

    top: 91px;

    opacity: 0;

    }

    a.arrowLeft:hover

    {

    background-image: url (.. / Images/arrowLeft.png);

    opacity: 0.5;

    }

    a.arrowRight

    {

    Width: 29px;

    height: 96px;

    position: absolute;

    float: right;

    margin: 0 auto;

    display: block;

    background-image: url (.. / Images/arrowRight.png);

    background-repeat: no-repeat;

    opacity: 0;

    left: 720px;

    top: 92px;

    }

    a.arrowRight:hover

    {

    background-image: url (.. / Images/arrowRight.png);

    opacity: 0.5;

    }

    Here are the things I did to solve problems:

    If I set the div as a container for absolute, the left button disappears.

    I get the same effect when I change the relative position.

    I tried to change the position of relative to the two buttons.

    I also tried to position the buttons outside the div hand and no go.

    How can I position the relative div under these controller button?

    Any help would be appreciated muchly.

    ~ THE

    I don't see a slider.  The code of your slide seems to have a style inline with the width: 0px which is not normal.    Width should be about 400 px.

    I suspect that your arrows need a much z-index superior to appear on the top layers of cursor.  But that's just a guess because I don't see a slider.

    Nancy O.

  • A full justification and display two pages do not work correctly on iOS 10

    I have installed iOS 10 yesterday on my iPad 2 Air but have found that the two functions do not work correctly in iBooks. First of all, full justification does not work when the font size is brought to a certain level. In other words, a complete justification works only when I reduce the police to a size too small. It then automatically left justification when I increase the font size to a comfortable level. This feature, however, works perfectly on iOS 9.3.5. Secondly, as already posted by a member of this community of support, the option to display two pages does not work correctly. Also, this feature stops working when the police is increased to a certain size.

    Someone at - it solutions?

    It is not a solution. Apparently, it's just how it is in the new iBooks. I would say that we all leave comments that we do not like it. This is a feature of iOS 10, so it won't go away unless we do a big noise about it. I just got my Mini iPad so I don't have to deal with.

    www.apple.com/feedback/iBooks_iOS.html

  • Don't display two pages does not correctly in the iOS 10

    I've upgraded my iPad to iOS 10 2 Air tonight, then went to continue reading a book that I bought recently through iBooks.  Display two pages, when the iPad is in landscape mode, does not appear now - unless I do the police really small.  If I increase the font size, while in the landscape to something more readable, I get only a single page view.

    I deleted and re-uploaded the book, but the behavior is the same.  I signed up in iBooks on iPad an another running ios 9.3.5 and display two pages work properly, with normal font sizes - sizes that won't let me see the same book in two page mode on iOS 10.

    Apple - help!  I really prefer the reading with the fashion landscape of two pages in iBooks.  I can't, however, seem to get this to work with anything other than tiny fonts.

    Has anyone else noticed this?

    I also noticed. Any solution?

  • Synchronization of the configuration shows two buttons

    I have correctly set up Firefox Sync and used Firefox for a while successfully Sync in the PC Windows standard user on 3 computers accounts. However, when I tried to sync the administrative account on a computer, I was unable to. Since then, whenever I'm doing a tools/configuration synchronization, or Tools/Options/synchronization on all my computers, only two buttons to the top: "Create a new account" and "I have an account". There is no button 'Manage account', not related to Unlink this computer from Sync, nothing. I tried all kinds of things and I looked a long time for help on this problem and have not found something to help. If I delete my account just to start and complete synchronization, it will work, or could I be causing other problems by doing this? Any other suggestions? Thank you.

    What do you see in the list of menu drop-down menu button Firefox?

    Is - this set up sync or synchronize now?

    If you have 'Set up sync' then you seem to have lost the configuration of the synchronization and you will have to redo the set up Sync.

    If this is not possible, then try to delete (or rename) the armor in the Firefox profile folder file and reset synchronization preferences on the topic: config page.

    You can use this button to go to the Firefox profile folder:

    • Help > troubleshooting information > profile directory: see file (Linux: open the directory;) Mac: View in the Finder)

    You can open the topic: config page through the address bar and to search for the prefs that begin with services.sync and reset set user prefs ("BOLD") through the context menu on the default value.

    If it still fails, then you can try a new profile.

    Create a new profile as a test to see if your profile is the source of the problems.

    See "create a profile":

    If the new profile works then you can transfer files from a profile in the new profile, but be careful not to copy files corrupted to avoid transporting on the problem.

  • Firefox displays two barely legible as a default fonts fonts. These came from an email that I opened. How can I get rid of them?

    Firefox displays two barely legible as the default fonts fonts. These came from an email that I opened. How can I get rid of them?

    You can write a check for corrupted fonts and duplicate and other police issues:

  • How can I have two buttons for 'new tab' in version 4?

    In version 3.x, there is a removable button on the toolbar for 'new tab' plus a button '+' at the end of the address of the open tab I could click to create a new tab.
    In version 4, I can have the removable button, but I do not see how to add the button at the end of the address of the open tab. I can move the single button at the end of the address window, but I can't have two buttons.
    Is it still possible?

    You must drag the button new tab (+) of the tabs to another toolbar toolbar to make the second button to appear.

    "Firefox > Options > toolbars" or "view > toolbars > customize.

  • I have an iMac (2015).  When I open Garageband, there are only two buttons on the control bar, play and stop.  No record button, rewind or ff.  Where are they and how can I make it appear?

    I have an iMac (2015). When I open Garageband, there are only two buttons on the control bar, play and stop. No record button, rewind or ff. Where are they and how can I make it appear?

    Try to enlarge the GarageBand window by dragging the corners of resizing.

    If she looks like this, your window is small:

    You can also try to click the double arrow at the end of the toolbar to reveal more options.

Maybe you are looking for