JAVA 可视化
2016-11-23 19:50
246 查看
1.禁用最大化窗口
f.setResizable(false);
2.去掉JFrame的java图标
Image icon = Toolkit.getDefaultToolkit().getImage("");
f.setIconImage(icon);
3.设置窗口为中央显示
a.适用所有窗口
public void centerWindow(Component component) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension scmSize = toolkit.getScreenSize();
Dimension size = component.getPreferredSize();
int width = component.WIDTH,
height = component.HEIGHT;
component.setLocation(scmSize.width / 2 - (width / 2),
scmSize.height / 2 - (height / 2));
}
centerWindow(f);
b.不是对所有的都适用,如对装有Image图象的ImagePanelPanel面板的窗口就不行
setLocationRelativeTo(null);
4.swing 多线程
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestThread extends JFrame {
JPanel jPanel1 = new JPanel();
JButton startButton = new JButton();
JButton stopButton = new JButton();
MyThread thread = null;
public TestThread() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
startButton.setText("start");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
startButton_actionPerformed(e);
}
});
stopButton.setText("stop");
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
stopButton_actionPerformed(e);
}
});
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(startButton, null);
jPanel1.add(stopButton, null);
}
void startButton_actionPerformed(ActionEvent e) {
if (thread != null)
thread.stop();
thread = new MyThread();
thread.start();
}
void stopButton_actionPerformed(ActionEvent e) {
if (thread != null)
thread.stop();
thread = null;
}
public static void main(String[] args) {
TestThread test = new TestThread();
test.setSize(300, 400);
test.show();
}
private class MyThread extends Thread {
public MyThread() {
}
public void run() {
while (true) {
try {
sleep(1000);
} catch (InterruptedException e) {
}
System.out.println("this is a test!");
}
}
}
}
f.setResizable(false);
2.去掉JFrame的java图标
Image icon = Toolkit.getDefaultToolkit().getImage("");
f.setIconImage(icon);
3.设置窗口为中央显示
a.适用所有窗口
public void centerWindow(Component component) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension scmSize = toolkit.getScreenSize();
Dimension size = component.getPreferredSize();
int width = component.WIDTH,
height = component.HEIGHT;
component.setLocation(scmSize.width / 2 - (width / 2),
scmSize.height / 2 - (height / 2));
}
centerWindow(f);
b.不是对所有的都适用,如对装有Image图象的ImagePanelPanel面板的窗口就不行
setLocationRelativeTo(null);
4.swing 多线程
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestThread extends JFrame {
JPanel jPanel1 = new JPanel();
JButton startButton = new JButton();
JButton stopButton = new JButton();
MyThread thread = null;
public TestThread() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
startButton.setText("start");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
startButton_actionPerformed(e);
}
});
stopButton.setText("stop");
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
stopButton_actionPerformed(e);
}
});
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(startButton, null);
jPanel1.add(stopButton, null);
}
void startButton_actionPerformed(ActionEvent e) {
if (thread != null)
thread.stop();
thread = new MyThread();
thread.start();
}
void stopButton_actionPerformed(ActionEvent e) {
if (thread != null)
thread.stop();
thread = null;
}
public static void main(String[] args) {
TestThread test = new TestThread();
test.setSize(300, 400);
test.show();
}
private class MyThread extends Thread {
public MyThread() {
}
public void run() {
while (true) {
try {
sleep(1000);
} catch (InterruptedException e) {
}
System.out.println("this is a test!");
}
}
}
}
相关文章推荐
- Java学习笔记01---可视化输入输出,数据类型转化,流程控制
- JAVA可视化编程-Windowbulider的安装
- 记一:Java之可视化界面swing设计
- java可视化
- 体验java可视化开发
- JAVA可视化开发工具:jigloo
- java可视化编程-eclipse安装windowbuilder插件(转载)
- java可视化编程之Frame容器
- Java之可视化日历小练习
- 用Eclipse,VE进行Java可视化界面设计
- 基于ARCGIS二次开发可视化开发环境搭建(JAVA)
- Myeclipse实现java可视化开发
- 对adult数据集建立朴素贝叶斯模型评估并可视化(awk+hive+java+mysql+echarts)
- Hibernate+Struts应用程序的JavaWebStudio 2005下快速、可视化开发 (转)
- java桌面应用开发可视化工具windowbuilder详细使用方法
- java中的可视化界面
- java可视化编程之Frame容器
- Java Calendar类简单应用:实现可视化日历
- java可视化编程-eclipse安装windowbuilder插件(转载)
- java学习应用:可视化窗口模拟基础聊天窗口(模仿QQ)