Results 1 to 3 of 3
  1. #1
    pradeep24 is offline Member
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default Unbale to setText to a label multiple times in same program

    Hi ,

    I am developing a java swing application. In which i want to set a different text to a label in same program ( in single JFrame). I dont want to use another JFrame instead i want to use setText method of java and set different text to a label at different intervals of time according to my need.

    I am using java 1.7 sdk and pupy linux as OS.
    Below i am giving u my source code.

    What i am doing is in constructor of class i am setting an image to JFrame and setting text "Welcom...". And when user clicks on this JFrame a method is called which will clear the text "Welcome.." and sets new text to another label "Enter...." and from there another method is called and it clears label "Enter..." and sets a text "Plzz wait..". and yet there are more methods, i havnt provided here.

    But what is happening is it shows welcome text and then directly Plzz wait..
    Its not showing text Enter... because control is finished after last method gets executed.

    My concern is i want to show all the setText (my messages) in a sequence. Without using another JFrame. There is no any user input other than user will click on first welcome page.

    So can someone help me to do so.



    public class BackgroundFrame extends javax.swing.JFrame {

    JLabel setTitle1;
    JLabel setTitle2;
    JLabel setTitle3;
    JLabel setTitle4;

    JLabel midTitle1;
    JLabel midTitle2;
    JLabel midTitle3;

    JLabel lblPleaseWait;
    JLabel lblTurnPage;

    static String scanResponse;
    static String printerStatus;
    String accountNo;

    public BackgroundFrame() throws IOException
    {
    initComponents();

    setTitle1 = new JLabel(); // Welcome To
    setTitle1.setBounds(250,220,950,150);
    setTitle1.setForeground(new Color(6,42,120));
    setTitle1.setFont(new Font("Caladia", Font.BOLD, 60 ));
    setTitle1.setOpaque(false);
    labelBackground.add(setTitle1);

    midTitle1 = new JLabel(); // Please Enter Your Passbook
    midTitle1.setBounds(50,270,950,150);
    midTitle1.setForeground(new Color(6,42,120));
    midTitle1.setFont(new Font("Caladia", Font.BOLD, 60 ));
    midTitle1.setOpaque(false);
    labelBackground.add(midTitle1);

    setTitle2 = new JLabel(); // Passbook Printing
    setTitle2.setBounds(150,320,950,150);
    setTitle2.setForeground(new Color(6,42,120));
    setTitle2.setFont(new Font("Caladia", Font.BOLD, 60 ));
    setTitle2.setOpaque(false);
    labelBackground.add(setTitle2);

    midTitle2 = new JLabel(); // From Last Updated
    midTitle2.setBounds(150,370,950,150);
    midTitle2.setForeground(new Color(6,42,120));
    midTitle2.setFont(new Font("Caladia", Font.BOLD, 60 ));
    midTitle2.setOpaque(false);
    labelBackground.add(midTitle2);

    setTitle3 = new JLabel(); // Kiosk
    setTitle3.setBounds(350,420,950,150);
    setTitle3.setForeground(new Color(6,42,120));
    setTitle3.setFont(new Font("Caladia", Font.BOLD, 60 ));
    setTitle3.setOpaque(false);
    labelBackground.add(setTitle3);

    midTitle3 = new JLabel(); // Page
    midTitle3.setBounds(350,470,950,150);
    midTitle3.setForeground(new Color(6,42,120));
    midTitle3.setFont(new Font("Caladia", Font.BOLD, 60 ));
    midTitle3.setOpaque(false);
    labelBackground.add(midTitle3);

    lblPleaseWait = new JLabel(); // Please Wait
    lblPleaseWait.setBounds(150,520,950,150);
    lblPleaseWait.setForeground(new Color(6,42,120));
    lblPleaseWait.setFont(new Font("Caladia", Font.BOLD, 60 ));
    lblPleaseWait.setOpaque(false);
    labelBackground.add(lblPleaseWait);

    scanResponse = pl.init_scan();
    scanResponse = "success";

    if(scanResponse.equalsIgnoreCase("success"))
    {
    setTitle1.setText("Welcome To");
    setTitle2.setText("Passbook Printing");
    setTitle3.setText("Kiosk");
    }
    else
    {
    setTitle2.setText("Kiosk Is Out Of Service");
    }
    }

    private void labelBackgroundMouseClicked(java.awt.event.MouseEv ent evt)
    {
    getPrinterInfo();
    }

    public void clearSetTitle()
    {
    setTitle1.setText("");
    setTitle2.setText("");
    setTitle3.setText("");
    }

    public void clearMidTitle()
    {
    midTitle1.setText("");
    midTitle2.setText("");
    midTitle3.setText("");
    }

    public void getPrinterInfo()
    {
    printerStatus = pl.get_status();
    printerStatus = "Online";

    if(printerStatus.equalsIgnoreCase("Online"))
    {
    System.out.println("inside getPrinterInfo");

    clearSetTitle();

    midTitle1.setText("Please Enter Your Passbook");
    midTitle2.setText("From Last Updated");
    midTitle3.setText("Page");

    try
    {
    Thread.sleep(2000);
    }
    catch (InterruptedException ex)
    {
    Logger.getLogger(BackgroundFrame.class.getName()). log(Level.SEVERE, null, ex);
    }

    getPassbookInfo();
    }
    else
    {
    setTitle2.setText("Kiosk Is Out Of Service");
    }

    }

    public void getPassbookInfo()
    {
    clearMidTitle();

    accountNo = pl.acquire_image();
    accountNo = "12345";

    lblPleaseWait.setText("Please Wait . . . .");

    // authenticationRequest();

    }

    public static void main(String args[])
    {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run()
    {
    try
    {
    new BackgroundFrame().setVisible(true);
    }
    catch (IOException ex)
    {
    Logger.getLogger(BackgroundFrame.class.getName()). log(Level.SEVERE, null, ex);
    }
    }
    });
    }

    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: Unbale to setText to a label multiple times in same program

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: Unbale to setText to a label multiple times in same program

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Calling another form's label.setText
    By N00Bie in forum New To Java
    Replies: 11
    Last Post: 02-19-2011, 03:34 AM
  2. write line multiple times
    By relith in forum New To Java
    Replies: 3
    Last Post: 10-27-2010, 08:38 AM
  3. Issue with saving multiple times to a variable
    By sidd0123 in forum New To Java
    Replies: 3
    Last Post: 06-06-2010, 02:02 AM
  4. calling action class multiple times
    By sindhu_shiva in forum Web Frameworks
    Replies: 0
    Last Post: 08-07-2009, 02:44 PM
  5. Playing an AudioInputStream multiple times
    By pmgallardo in forum Advanced Java
    Replies: 6
    Last Post: 03-09-2009, 04:29 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •