java swing 示例_JAVA简单Swing图形界面应用演示样例
JAVA簡單Swing圖形界面應用演示樣例
package org.rui.hello;
import javax.swing.JFrame;
/**
* 簡單的swing窗體
* @author lenovo
*
*/
public class HelloSwing {
public static void main(String[] args) {
JFrame frame=new JFrame("hello Swing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,200);
frame.setVisible(true);
}
}
package org.rui.hello;
import java.util.concurrent.TimeUnit;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* JFream 中加入 一個JLabel來使事情變得更有趣
* @author lenovo
*
*/
public class HelloLabel {
public static void main(String[] args) throws InterruptedException {
JFrame frame=new JFrame("hello swing");
JLabel label=new JLabel("A label");
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,100);
frame.setVisible(true);
TimeUnit.SECONDS.sleep(1);
label.setText("Hey! this is Different!");
}
}
package org.rui.hello;
import java.util.concurrent.TimeUnit;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
/**
* swing 有它自已的專用線程來接收UI事件并更新屏幕
*
* @author lenovo
*
*/
public class SubmitLabelManipulationTask {
public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame("Hello Swing");
final JLabel label = new JLabel("A Label");
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 100);
frame.setVisible(true);
TimeUnit.SECONDS.sleep(1);
//專用線程
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
label.setText("hey! this is different");
}
});
}
}
package org.rui.hello;
import java.util.concurrent.TimeUnit;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class SubmitSwingProgram extends JFrame {
JLabel label;
public SubmitSwingProgram() {
super("hello swing");
label = new JLabel("A Label");
add(label);
setSize(300, 100);
setVisible(true);
}
//
static SubmitSwingProgram ssp;
public static void main(String[] args) throws InterruptedException {
//實例對象
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ssp = new SubmitSwingProgram();
}
});
TimeUnit.SECONDS.sleep(1);
//設置改變文字
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
ssp.label.setText("hey! this is different!");
}
});
}
}
package org.rui.hello;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
* 這可能是一個你想要自已使用的工具,
* 要想使用它,你的應用就必須位于一個JFrame中
* 靜態的run方法能夠將視窗的標題設置為類的簡單名
* @author lenovo
*
*/
public class SwingConsole {
public static void run(final JFrame f, final int width, final int height) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
f.setTitle(f.getClass().getSimpleName());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(width,height);
f.setVisible(true);
}
});
}
}
總結
以上是生活随笔為你收集整理的java swing 示例_JAVA简单Swing图形界面应用演示样例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: get+php+mysql_Apache
- 下一篇: 怎么更改iPhone苹果手机的屏幕键盘为