mr.game
شنبه 21 بهمن 1396, 20:55 عصر
دوستان من میخوام تایمری که گذاشتم روی swing عمل کنه و نمایش داده بشه ، کجای کارم اشتباهه ؟ :متفکر:
package Tamrin;
import javax.swing.*;
import java.awt.*;
public class Swing {
static Thread thread=new Thread();
public static int i=0;
public static void main(String[] args) {
Swing swing=new Swing();
swing.ui();
for (int t=0;t<60;t++){
try {
thread.sleep(1000);
System.out.println(t);
i--;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void ui(){
Dimension dimension=Toolkit.getDefaultToolkit().getScreenSiz e();
int x = dimension.width;
int y = dimension.height;
JFrame jFrame=new JFrame("Esm Famil");
jFrame.setBounds(x/4,y/4,x/2,y/2);
jFrame.setDefaultCloseOperation(WindowConstants.EX IT_ON_CLOSE);
jFrame.setVisible(true);
jFrame.setLayout(null);
JPanel jPanel=new JPanel(null);
jPanel.setVisible(true);
jPanel.setBounds(0,0,x/2,y/2);
jPanel.setBackground(Color.cyan);
jFrame.add(jPanel);
JLabel Timer=new JLabel(String.valueOf(i));
Timer.setVisible(true);
Timer.setBounds(x/4,0,50,50);
Timer.setHorizontalAlignment(JLabel.RIGHT);
jPanel.add(Timer);
}
}
package Tamrin;
import javax.swing.*;
import java.awt.*;
public class Swing {
static Thread thread=new Thread();
public static int i=0;
public static void main(String[] args) {
Swing swing=new Swing();
swing.ui();
for (int t=0;t<60;t++){
try {
thread.sleep(1000);
System.out.println(t);
i--;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void ui(){
Dimension dimension=Toolkit.getDefaultToolkit().getScreenSiz e();
int x = dimension.width;
int y = dimension.height;
JFrame jFrame=new JFrame("Esm Famil");
jFrame.setBounds(x/4,y/4,x/2,y/2);
jFrame.setDefaultCloseOperation(WindowConstants.EX IT_ON_CLOSE);
jFrame.setVisible(true);
jFrame.setLayout(null);
JPanel jPanel=new JPanel(null);
jPanel.setVisible(true);
jPanel.setBounds(0,0,x/2,y/2);
jPanel.setBackground(Color.cyan);
jFrame.add(jPanel);
JLabel Timer=new JLabel(String.valueOf(i));
Timer.setVisible(true);
Timer.setBounds(x/4,0,50,50);
Timer.setHorizontalAlignment(JLabel.RIGHT);
jPanel.add(Timer);
}
}