javaGUI解决闪屏问题
2015-07-24 12:30
483 查看
javaGUI解决闪屏问题可以通过继承JPanel来实现,特别简单,因为JPanel有已经实现的解决闪屏的方法
JFrame jfm=new JFrame();
this.setDoubleBuffered(true);
JFrame jfm=new JFrame();
this.setDoubleBuffered(true);
package demo.wl; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class DemoGUI extends JPanel{ public void init(){ JFrame jfm=new JFrame(); //this.setDoubleBuffered(true);//这个就是JPnel自带的双缓冲技术 jfm.add(this);//把JPanel组件加到窗口上来 jfm.setTitle("GUI"); jfm.setVisible(true); jfm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfm.setBounds(0, 8, 820, 620); jfm.setLocationRelativeTo(null); jfm.setResizable(false); new Thread(new MyThread()).start(); } public static void main(String[] args) { new DemoGUI().init(); } @Override public void paint(Graphics g) { super.paint(g); g.setColor(Color.GRAY); g.drawRect(20, 40, 750, 525); g.fillRect(200, 110, 50,50); for(int i=1;i<=50;i++){ for(int j=1;j<=35;j++){ g.drawLine(20,15*j+40,770, 15*j+40); } g.drawLine(20+15*i, 40, 20+15*i, 565); } } public class MyThread implements Runnable{ @Override public void run() { while(true){ repaint(); try { Thread.sleep(1); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
相关文章推荐
- UICollectionView的简单使用
- IOS开发UI基础--数据刷新
- java GUI游戏界面问题 play,exit操作
- iOS8开发~UI布局(二)storyboard中autolayout和size class的使用详解 f
- POJ 2457--Part Acquisition 【spfa最短路 + STL路径输出】
- 如果你在iphone6plus下看到[UIScreen mainScreen].scale不是3.0
- Maven的Build过程
- [Java Web]EasyUI中Calendar预设时间的解决
- UITableView的简单使用
- IOS UILocalNotification 本地通知
- iOS 编程 利用UIScrollView 编写无缝循环显示图片
- 安卓使用merge标签和include优化UI布局
- uep开发——财务管理系统的总结
- 如何扩展EasyUI在页面中立即显示选中的本地图片
- Implement Queue using Stacks
- gulp插件(gulp-jmbuild),用于WEB前端构建
- Android高仿QQ v4.7.0全新UI
- 从客户端中检测到有潜在危险的 Request.Form 值
- emulator: ERROR: x86 emulation currently requires hardware acceleration!Please ensure Intel HAXM is
- uilabel自适应高度