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