📄 frame1.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -