public void layoutContainer (Container target) {
synchronized (target.getTreeLock()) {
Insets insets = target.getInsets();
int maxwidth = target.getSize().width - (insets.left + insets.right);
int nmembers = target.getComponentCount();
if (maxwidth < 0 || nmembers == 0) return; int rowh = 0, lastVisible = -1;
for (int i = nmembers - 1; i >= 0; i--) {
Component m = target.getComponent(i);
if (m.isVisible()) {
if (lastVisible == -1) lastVisible = i;
Dimension d = m.getPreferredSize();
if (d.height > rowh) rowh = d.height;
}
}
if (lastVisible == -1 || rowh == 0) return; int x = 0, y = insets.top + vgap;
for (int i = 0 ; i < nmembers ; i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
if (i == lastVisible) d.width = maxwidth - x;
m.setBounds(x, y + (rowh - d.height) / 2, d.width, d.height);
x += hgap + d.width;
}
}
}
}
把这个变成多线程,新手求帮助
synchronized (target.getTreeLock()) {
Insets insets = target.getInsets();
int maxwidth = target.getSize().width - (insets.left + insets.right);
int nmembers = target.getComponentCount();
if (maxwidth < 0 || nmembers == 0) return; int rowh = 0, lastVisible = -1;
for (int i = nmembers - 1; i >= 0; i--) {
Component m = target.getComponent(i);
if (m.isVisible()) {
if (lastVisible == -1) lastVisible = i;
Dimension d = m.getPreferredSize();
if (d.height > rowh) rowh = d.height;
}
}
if (lastVisible == -1 || rowh == 0) return; int x = 0, y = insets.top + vgap;
for (int i = 0 ; i < nmembers ; i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
if (i == lastVisible) d.width = maxwidth - x;
m.setBounds(x, y + (rowh - d.height) / 2, d.width, d.height);
x += hgap + d.width;
}
}
}
}
把这个变成多线程,新手求帮助
解决方案 »
- rest cxf osgi servicemix问题
- 初学spring 报的一个错不知道怎么处理
- Struts2错误求教,在线等!我是个菜鸟看不懂,大家来帮忙看看。
- 新手 问: 开发Ejb3的应用 用什么平台啊?
- 连接数据库的时候出现的问题
- 大家都知道对象持久化技术中的缓存机制是为了提高系统的性能 ??怎么去理解(高分求助高手)
- Hibernate在进行多条数据的查询和保存时报错,大虾帮忙啊
- 如何在Spring mvc下实现BeanNameAutoProxyCreator 动态代理?????
- Best Java Book for Experts
- jms和socket有什么关系和异同?
- 用dwr,要把bean集合传递给页面
- 学生信息管理系统
thread.start();
thread.join();
public void run(){
//do anything
}
}-----------下面是把ThreadA进行多线程------------
ThreadA a= new ThreadA()Thread thread = new Thread(a)
thread.start();
thread.join();
public class GuiLastWideLayou{
public void layoutContainer (Container target) {
Thread t = new LayoutContainerThread(target);
t.start();
}
}
class LayoutContainerThread extends Thread{
private Container target;
public LayoutContainerThread(Container t){
target = t;
}
public void run(){ Insets insets = target.getInsets();
int maxwidth = target.getSize().width - (insets.left + insets.right);
int nmembers = target.getComponentCount();
if (maxwidth < 0 || nmembers == 0) return; int rowh = 0, lastVisible = -1;
for (int i = nmembers - 1; i >= 0; i--) {
Component m = target.getComponent(i);
if (m.isVisible()) {
if (lastVisible == -1) lastVisible = i;
Dimension d = m.getPreferredSize();
if (d.height > rowh) rowh = d.height;
}
}
if (lastVisible == -1 || rowh == 0) return; int x = 0, y = insets.top + vgap;
for (int i = 0 ; i < nmembers ; i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
if (i == lastVisible) d.width = maxwidth - x;
m.setBounds(x, y + (rowh - d.height) / 2, d.width, d.height);
x += hgap + d.width;
}
}
}
}
}
public class GuiLastWideLayou{
public void layoutContainer (Container target) {
LayoutContainerThread t = new LayoutContainerThread(target);
Thread thread = new Thread(t);
t.start();
}
}
class LayoutContainerThread implements Runnable{
private Container target;
public LayoutContainerThread(Container t){
target = t;
}
public void run(){ Insets insets = target.getInsets();
int maxwidth = target.getSize().width - (insets.left + insets.right);
int nmembers = target.getComponentCount();
if (maxwidth < 0 || nmembers == 0) return; int rowh = 0, lastVisible = -1;
for (int i = nmembers - 1; i >= 0; i--) {
Component m = target.getComponent(i);
if (m.isVisible()) {
if (lastVisible == -1) lastVisible = i;
Dimension d = m.getPreferredSize();
if (d.height > rowh) rowh = d.height;
}
}
if (lastVisible == -1 || rowh == 0) return; int x = 0, y = insets.top + vgap;
for (int i = 0 ; i < nmembers ; i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
if (i == lastVisible) d.width = maxwidth - x;
m.setBounds(x, y + (rowh - d.height) / 2, d.width, d.height);
x += hgap + d.width;
}
}
}
}
}
但是都不能通过编译
如果做web开发,本身就是多线程,你的代码这样可以了,不需要改。
是这样的,我现在要的是将这个layoutContainer 这个方法的性能提高2X,当我点击某个按钮的时候,会执行到这个方法,执行一次这个方法弹出一个窗口,一共要弹出2个,在运行的时候2个窗口出来有个时间差,我要的就是把这个时间差降低,所以我就用多线程。各位支个招啊
我不知道你是想干什么, 但是既然你知道编译不过,难道不知道为什么编译不过么??很明显的错误啊.LayoutContainerThread t = new LayoutContainerThread(target);
Thread thread = new Thread(t);
t.start()既然你都把t对象丢到thread里面去了,为什么不是thread.start(),而要写成t.start()呢??