Setting the text on a label

Ok, I am new to writing Java programs and I am having trouble setting the text on a label. I think I am following the syntax perfectly but my compiler wont accept it. This used to work for me then all of a sudden it didnt work.
Here is the code that I was writing. I am trying to set the text of the Label lab1. What am I doing wrong?
import java.awt.*;
import java.applet.*;
public class exer4 extends Applet
Button but1;
TextField txt1;
TextField txt2;
Label lab1;
     public void init()
     but1 = new Button("Click Me");
     add(but1);
     txt1 = new TextField(5);
     add(txt1);
     txt2 = new TextField(5);
     add(txt2);
     lab1 = new Label("This is a label");
     add(lab1);
}

Try this
import java.awt.*;
import java.applet.*;
import java.util.*;
public class pay extends Applet
Button but1;
TextField txt1;
TextField txt2;
Label lab1;
public void init()
lab1 = new Label("This is a label");
Panel pan = new Panel();
pan.add(lab1);
add(pan);
but1 = new Button("Click Me");
add(but1);
txt1 = new TextField(5);
add(txt1);
txt2 = new TextField(5);
add(txt2);
ps see you around

Similar Messages

  • Can I set the text color in a Label?

    Hi everyone ~
    Can I set the font color in PP? I only found that there is a "setBackground".. but I want to set the color within a Label.
    Thanks!
    Gary

    Fixed it!
    There was a global style for s|Label and since the Spark button uses one of these for the text, that was it.

  • Newbie iPhone: How do I programatically set the text of a UIBarButtonItem?

    Hello,
    This is probably really more of a question on IBOutlets but here goes. I want to have an updateable label on my Toolbar. A label doesn't seem to "stick" on the toolbar so I figured I would drop a UIBarButtonItem on it and then just update the Title property of it to change the text as I needed. Problem is I can't figure out how to get a reference to the UIBarButtonItem in my code.
    With a pure label control, I can drag from the File's Owner to the label in my view to make it an outlet for my ViewController and then access the text property of the label in code. With the UIBarButtonItem, I can't make it an outlet. I know the button is more of an action thing but I don't need to respond to taps, I just want to change the text.
    Thanks for any help,
    Tom

    Tom,
    You should be able to assign the UIBarButtonItem to an outlet as long as:
    1) you have defined an instance variable in FilesOwner of UIBarButtonItem and prefixed it with "IBOutlet".
    2) FilesOwner is set to your custom view controller in the Interface Builder's Inspector panel. If it still thinks it's a standard UIViewController it won't pick up your custom outlets.
    All that being said, I'm not sure you can change the title without using a custom view. The default UIBarButtonItem has an initWithTitle: initializer that may be static (perhaps others know of a way to change it once set). But you can define a custom view for the button. That gives you the ability to add a UILabel and programmatically set the text of the label.
    Cheers,
    George

  • How do you set the text of a Hyperlink component in code

    I am using Visual Web pack in NB 6.0. How do you set the text of a hyperlink component in code?
    Please see screenshots at
    http://coba.usf.edu/departments/isds/faculty/agrawal/projects/java/
    I have a hyperlink in a grid panel. I am using
    hyperlink1.setText("Hello"); in prerender(),
    but the Hyperlink shows up with the text "Hyperlink", whereas I was expecting "Hello". However,
    hyperlink1.setUrl("http://www.usf.edu"); works as expected.
    I tried nesting a static text in the hyperlink as suggested in the Creator guide (ed 2, Google project). I deleted the "Hyperlink" text in the properties editor but then the page turned out blank.
    Thanks
    Manish

    Hi Manish,
    Great to know you were able to fix your issue. The following blog entry has the list of resources you would like to look at for future.
    http://blogs.sun.com/NetBeansSupport/entry/useful_resources_for_visual_web
    Thanks
    K

  • How to set the 'text' property of a 'Header' region dynamically?

    Hi,
    I have a requirement to display the 'text' property of a 'Header' region, based on a query.
    So I need to set the text property programatically in CO.
    Can I use setText("..") by getting the handler to the 'Header' region?
    If so, How to get the handler for the 'Header' region?
    Message was edited by:
    user594528

    How to get the handler for the 'Header' region to call the setText()?
    OAHeaderBean Header1 = (OAHeaderBean)...........................
    Header1.setText("....");

  • How to set the text as an image

    Is there a way to set the text to automatically change to an image? (In preference panel, you select "Sow text imaging indicator", then there comes a yellow sign over the text, meaning that the text will be a graphic in the browser) Some text does change to a graphic but some does not. It´s very annoying cause the text sometimes changes in the browser, some don´t. So is there not a way to select which text changes to a graphic?

    Okay I made a new text box and changed the font until the little graphic appeared. Now I know, but, I also know that a lot of the font I tried would not be on someone else's computer (specially windows) but it would not have converted I guess it would have been substituted. That is really not good because the look would be very different. Should we force a conversion then to insure that it looks like what we want? Then we no longer have any text we have mostly graphics and is that not bad to be found by the search engines?
    This is so complicated!
    Mireille

  • How to change the size of the text inside a label?

    Hello,
    I would like to change the size of the text inside a label.
    Is there any way to do it Web DynPro?

    Hello Roy,
    Not possible. WDLabelDesign contains only 2 values: STANDARD and LIGHT. As workaround you can use TextView. It supports a lot of "designs" (e.g. label_small).
    Best regards, Maksim Rashchynski.

  • How do make the text on a label Bold?

    Simple question: How do make the text on a label Bold?

    use html : label.setText("<html><body><b>TestText</b></body>/html>");
    regards,
    Tim

  • How do you set the Text in an Accordion Interaction?

    When trying to set the text in the Accordion Interaction, it behaves very strange. You can't set it. It starts out at 13 and then changes to either 10 or 30.
    Can anyone give some advise on how to set this?
    Thanks.

    Hello,
    Logged that bug (as well, have a long list). Workaround depends on your hardware: for some scrolling the mouse wheel will allow to change font size (doesn't work for me). On my Lenovo Thinkpad I have to use the trackpad, that has a scrollbar, to change the font size. Very cumbersome, was promised that it would soon be patched, crossing my fingers.
    Lilybiri

  • How to Set the Text of an Onstage TextField?

    I'm trying to set an onstage TextField instance's "text" property, while maintaining embedded fonts and its onstage appearance.
    Problem Encountered: Text doesn't show up when setting text via ActionScript on an on-stage TextField w/ embedded text.
    Workaround: Create and assign a TextFormat object:
    defaultTextFormat = new TextFormat('Arial', 100, 0x000000, true, true);
    Annoyance: This defeats the purpose of styling text with the IDE.
    Possible Solution: Import the embedded font to the library and export for ActionScript?

    My problem was actually that merely setting the *text* property caused my dynamic TextField w/ embedded font to not display any text. BUT, I just re-tested this with a new file, and the problem doesn't occur. Only thing I can think of is -- my FLA was created with an older version of Flash... possibly MX 200(4?). Could this be the issue?

  • Setting the text in ComboBox when nothing is selected

    Hi, I want to ask you, whether there is any possibility to set text of a JComboBox, when nothing is selected. I want something like "Choose One" to be shown when no option is selected. Thanks for any help.

    Never mind, I got it, you have tu create your own renderer and set the text for null value selected

  • Setting the text content of an Entity

    Hi all
    In some java code I'm writing, if I set the text content of an element, it wipes out any sub-elements that were there before. I just want to confirm that this is correct behavior and that I am doing this correctly. If an element has text, it can't have other children, correct?
    code from my TreeModel is below
         public void valueForPathChanged(TreePath arg0, Object arg1) {
              Object o = arg0.getLastPathComponent();
              if (o instanceof Attr) {
                   Attr attr = (Attr) o;
                   attr.setValue(arg1.toString());
                   mTree.updateUI();
              if (o instanceof Element) {
                   Element el = (Element) o;
                   //el.setNodeValue(arg1.toString());
                   el.setTextContent(arg1.toString());
                   mTree.updateUI();
              }

    I was wrong you can have text and data I had just screwed up my tree model :)

  • TabStripLayout-View: Where to set the text?

    Hello,
    I am using a view of the kind TabStrip. For your understanding> Not a normal view with a tabstrip. It is a view similar to Gridlayout, just TabStripLayout.
    I can not find where to set the text for the individual tabs, e.g. TAB1, TAB2 etc.
    Does anzbodz know?
    Regards Thank Mario

    I assume you are using a TabStrip layout of a viewset.  The tab 'captions' are set in the properties for the viewset.  In the explorer outline, expand Windows and click on the ViewSet and in the properties for the ViewSet it will have the captions listed for the tabs and you can change the text there.
    Be aware that the tab strip layout for viewsets is a bit limited.  As far as I can tell the navigation plugs between views do not work.  There are other forum questions/answers on how to use a normal TabStrip element rather than a viewset to get around this.
    -Cindy

  • Setting the text in label components

    Please help with the following very simple code. I have done
    everything I am supposed to do according to the in-program help,
    the Flash 8 Actionscript bible and every other source I can find
    online, yet the following code will not generate a simple label
    component. I've checked to insure it is not placed too far in any
    direction and even played around with its styles, setting the font
    and font color -
    nothing. It's been 2 hours now... I'm really starting to
    hate components.
    Without exaggerating, it took me roughly 4 hours to figure
    this out: I replaced all of the "getNextHighestDepth"s with numbers
    (starting the numbering at 0) and everything showed up. Turns out
    the label code was working, but the label was getting replaced by
    the next component called in the code because they were all at the
    same depth. I thought getNextHighestDepth() was supposed to prevent
    this!

    >> I have done everything I am supposed to do according
    to the in-program help
    Not exactly. You should have been using the DepthManager
    instead of getNextHighestDepth.

  • How do you set the fontSize of a label in AS?

    I am tinkering with a neat little component I found, and I
    added a few labels to it. In the AS code there are now four labels.
    I wanted to change the default font size on one of the labels,
    which I know how to do in mxml but I don't really understand how
    that translates to a component in ActionScript.
    Imitating the way height and width were set, I tried:
    label.fontSize="10";
    but this gives me an error 1119 "access to possibly undefined
    property fontSize through a reference with static type
    mx:controls.label"
    Can someone tell me how to set the font size within an AS
    component?
    M.

    quote:
    Originally posted by:
    Greg Lafrance
    Actually you may need to do this, but don't name your objects
    "label" otherwise you will have a conflict with Flex property
    names.
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    private function clickHandler():void{
    lbl.setStyle("fontSize", 30);
    ]]>
    </mx:Script>
    <mx:Label text="One"/>
    <mx:Label text="Two"/>
    <mx:Label text="Three"/>
    <mx:Label id="lbl" text="Four"/>
    <mx:Button label="Test" id="btn"
    click="clickHandler()"/>
    </mx:Application>
    This is mxml though right? How could you translate this into
    AS? This thing is an AS component.
    By the way I'm not using the name label I just changed to
    that to make the code generic / easier to understand. The label
    names are minLabel, maxLabel, and topLabel
    M.

Maybe you are looking for