Dynamically update the Label & set Bounds constant between 2 Label(Thread)
strong textpackage xcada;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import javax.swing.JButton;
import javax.swing.JLabel;
public class MyNew3 extends javax.swing.JFrame {
private int q;
private String r;
private String data[ ]={ };
private String tagNo;
private String findTagNo[ ]={ };
private JButton button1[];
private int m=0;
private String t3="";
private String str5="";
private String t2="";
public MyNew3( String t2,String t3,int q)
{
initComponents();
this.q=q;
this.t2=t2;
this.t3=t3;
StringThread th = new StringThread ();
th.start();
}
MyNew3() {
}
private JLabel createlabel(int i,String tagNo)
{
final String tagNo1=tagNo;
System.out.println(""+i);
JLabel label1= new JLabel();
this.button1[i]=new JButton();
this.jPanel1.add(label1);//***Here is error coming..***
// System.out.println("I m not here");
System.out.println("I m here");
jPanel1.add(button1[i]);
label1.setText(data[i]);
button1[i].setText("Update");
label1.setBounds(110,100+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i, 375, 20);
button1[i].setBounds(110,120+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i+i, 75, 15);
label1.setFont(new Font("Tahoma", Font.BOLD, 14));
button1[i].addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
MyNew4 form4=new MyNew4(tagNo1);
}
});
return label1;
//return button1;
}
public void display() {
try
{
Connection con=(Connection) ConnectionFactory.getConnection();
String sql1="SELECT * FROM people";
PreparedStatement ps2=(PreparedStatement) con.prepareStatement(sql1);
ResultSet rs2=ps2.executeQuery();
System.out.println(rs2);
while(rs2.next())
{
this.str5+=rs2.getString("Type")+":"+rs2.getString("Temp")+"Tag Number :"+rs2.getString("Tag")+"Unit :"+rs2.getString("Unit")+"\n#";
data=str5.split("#");
m++;
}
}
catch(Exception e)
{
}
JLabel label[]=new JLabel[m];
this.button1=new JButton[m];
System.out.println(""+m);
for(int i=0;i<m;i++)
{
this.findTagNo=data[i].split("Tag Number :");
this.findTagNo=findTagNo[1].split("Unit :");
label[i]=createlabel(i,findTagNo[0]);
}
}
}
class StringThread extends Thread
{
StringThread()
{
super();
}
@Override
public void run ( )
{
while(true)
{
try
{
new MyNew3().display();
// System.out.println("hi11");
this.sleep(1000);
}
catch(Exception e)
{
System.out.println("Hi");
System.out.println(e.toString());
}
}
}
}
sir, i m facing problem in Dynamically update the label. when i m changing the the value in database , its dynamically not updated
prblem is jPanel.add(label11); and also not setting the bounds properly...
plz resolve it
View Answers
Ads
Related Tutorials/Questions & Answers:
Advertisements
How to set Marathi font to Label??
How to
set Marathi font to
Label?? Hello, I am doing one project in java-Swing Farm Management i want to
set Marathi
label in that so how i can?
plzzzz help me its urgent
Label
Label
A displayed
label object is known as the
Label. Most
of the times
label is used... the functioning of the next text field. A
label is
also restricted to a single line
ModuleNotFoundError: No module named 'label'
ModuleNotFoundError: No module named '
label' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
label'
How to remove the ModuleNotFoundError: No module named '
label'
ModuleNotFoundError: No module named 'label'
ModuleNotFoundError: No module named '
label' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
label'
How to remove the ModuleNotFoundError: No module named '
label'
janusgraph find edge with label
graph server. I want to find all the edges with a particular
label.
How to find edge with
label in janusgraph?
Thanks
Hi,
You can use following query for find edge with
label:
g.V().hasLabel('MyLevel')
Thanks
Struts2.2.1 label Tag Example
Struts2.2.1
label Tag Example
The
label tag is used to renders an HTML
LABEL that allow to output <s:
label name=? ? value=? ? /> combination that has... will shows how to implement the
label tag in the
Struts2.2.1 --
First we create
select the foreground color for a label
select the foreground color for a label (Using JScrollBar) Write a program that uses scroll bars to select the foreground color for a
label, Three horizontal scroll bars are used for selecting the red, green, and blue components
Setting Multi-Line label on the Button
Setting Multi-Line
label on the Button
This section shows you how to
set the multi line
label
on the button in Java Swing Applications.
This program uses html class
Label n Dropdown Issue
Label n Dropdown Issue Hi guys,
Some how Iam able to receive the data for labels, dropdowns.
I created one array with the size of
label, and statred for loop, inside this I created one more array of type above created
Dropdown and label issue
Dropdown and
label issue This is Venkat from Hyderabad,India.Working as a JavaDeveloper herein.
Could you please read the code n give your valuable... array with the size of
label, and statred for loop, inside this I created one
ModuleNotFoundError: No module named 'edc-label'
ModuleNotFoundError: No module named 'edc-
label' Hi,
My Python... 'edc-
label'
How to remove the ModuleNotFoundError: No module named 'edc-
label' error?
Thanks
Hi,
In your python environment you
enable text box and label on selection
enable text box and
label on selection hello,
Please tell me how to enable
label and text box on selection of drop down list box.
in drop down list box all values come from database.
please reply
J2ME Label Example
are
using setLabel to
set the new
label to the ItemString. We are replacing the new...
J2ME
Label Example
This is the simple create
label example in which we create an StringItem
Difference between Timer and Thread?
Difference
between Timer and
Thread? Can anyone tell me about the difference
between Timer and
Thread, Why we need to have Timer in case we have
Thread implimentation startegy in Java