frame1.java

来自「一个java编写」· Java 代码 · 共 64 行

JAVA
64
字号
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.* ;
public class Frame1 extends JFrame
{
	JPanel contentPane;
	BorderLayout borderLayout1 = new BorderLayout();
	Thread memoryWatcher ;
	DecimalFormat df = new DecimalFormat( "#0.00" ) ;
	long tot = 0 ;
	long free = 0 ;
	long used = 0 ;
	Runtime rt ;
	public Frame1()
	{
		enableEvents(AWTEvent.WINDOW_EVENT_MASK);
		rt = Runtime.getRuntime() ;
		try
		{
			jbInit();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	private void jbInit() throws Exception
	{
		contentPane = (JPanel) this.getContentPane();
		contentPane.setLayout(borderLayout1);
		this.setSize(new Dimension(400, 300));
		this.setTitle("Frame Title");
		memoryWatcher = new Thread()
		{
			public void run()
			{
				while( true )
				{
					tot = rt.totalMemory() ;
					free = rt.freeMemory() ;
					used = tot - free ;
					System.out.println( df.format( used / 1024.0d ) + "k/" +  df.format( tot / 1024.0d ) + "k" ) ;
					rt.gc();
					try
					{
						this.sleep( 5000 );
					}
					catch( InterruptedException ex )
					{ }
				}
			}
		} ;
		memoryWatcher.start();
	}
	protected void processWindowEvent(WindowEvent e)
	{
		super.processWindowEvent(e);
		if (e.getID() == WindowEvent.WINDOW_CLOSING)
		{
			System.exit(0);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?