| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 571 人关注过本帖
标题:[求助]JAVA程序内存使用在JCREATOR调试不成功...
取消只看楼主 加入收藏
nwtcharisma
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-9-13
收藏
 问题点数:0 回复次数:0 
[求助]JAVA程序内存使用在JCREATOR调试不成功...

哥哥姐姐们帮个忙...找出错误来..万分感激..
package myprojects.jmemorydemo;

import javax.swing.UIManager;
import java.awt.*;


public class JMemoryDemo {
private boolean packFrame = false;


public JMemoryDemo() {
MainFrame frame = new MainFrame();

if (packFrame) {
frame.pack();
}
else {
frame.validate();
}

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height)
/ 2);
frame.setVisible(true);
}

public static void main(String[] args)
{
new JMemoryDemo();
}
}
===================================================
package myprojects.jmemorydemo;
import javax.swing.*;

public class ProgressThread extends Thread {
JProgressBar pbar;
JLabel label;

public ProgressThread(JProgressBar pbar,JLabel label) {
this.pbar=pbar;
this.label=label;
}
public void run() {


int min=0;
int max=100;
int free=0;
int totle=0;
int status=0;

pbar.setMinimum(min);
pbar.setMaximum(max);
pbar.setValue(status);
while(true){
try{
totle=(int)(Runtime.getRuntime().totalMemory()/1024);
free=(int)(Runtime.getRuntime().freeMemory()/1024);
}catch(Exception e){
e.printStackTrace();
}
label.setText("Free Memory :"+(int)(Runtime.getRuntime().freeMemory()/1024)+"K"+" Totle Memory Allo
cated :"
+(int)(Runtime.getRuntime().totalMemory()/1024)+"K");
status=(int)(free*100/totle);
pbar.setValue(status);
pbar.setString("Free Momery "+ status+"%");
try{
this.sleep(1000);
}catch(InterruptedException err){}
}

}

}


===============================================
package myprojects.jmemorydemo;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MainFrame extends JFrame {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JProgressBar jProgressBar1 = new JProgressBar();
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();


public MainFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
(MainFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(304, 215));
this.setTitle("JMemoryDemo");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
jLabel1.setText("Memory Monitor");
jProgressBar1.setOrientation(JProgressBar.VERTICAL);
jProgressBar1.setFont(new java.awt.Font("Dialog", 0, 14));
jProgressBar1.setToolTipText("");
jProgressBar1.setStringPainted(true);
jLabel2.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel2.setText("");
contentPane.add(jProgressBar1, BorderLayout.CENTER);
contentPane.add(jLabel1, BorderLayout.NORTH);
contentPane.add(jLabel2, BorderLayout.SOUTH);

ProgressThread pThread = new ProgressThread(this.jProgressBar1,this.jLabel2);
pThread.start();
}

protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
======================================================================

[此贴子已经被作者于2007-9-13 13:09:30编辑过]

搜索更多相关主题的帖子: JAVA 内存 JCREATOR 调试 
2007-09-13 13:07
快速回复:[求助]JAVA程序内存使用在JCREATOR调试不成功...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018467 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved