Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package games.pokenation.client;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.EventQueue;
- import java.awt.HeadlessException;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowListener;
- import java.lang.reflect.InvocationTargetException;
- import javax.swing.JApplet;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTabbedPane;
- public class TestApplet extends JFrame {
- private JLabel memoryLabel;
- public void init() {
- memoryLabel = new JLabel("Hit the update button");
- JButton updateMemory = new JButton("Update Memory Info");
- updateMemory.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int megs = 7;
- byte[][] bytes = new byte[2000][];
- int i = 0;
- while (true) {
- try {
- bytes[i % 2000] = new byte[megs * 1024 * 1024];
- i++;
- } catch (OutOfMemoryError e1) {
- bytes = null;//-.-
- break;
- }
- }
- bytes = null;//-.-
- final Runtime rt = Runtime.getRuntime();
- rt.gc();
- rt.gc();
- final long maxMem = rt.maxMemory();
- final long totalMem = rt.totalMemory();
- final long freeMem = rt.freeMemory();
- final double bpmb = 1024 * 1024;
- memoryLabel.setText(String.format("Max=%1.2f MB Total=%1.2f MB Free=%1.2f MB Used=%1.2f MB", maxMem / bpmb,
- totalMem / bpmb, freeMem / bpmb, (totalMem - freeMem) / bpmb));
- }
- });
- add(memoryLabel, BorderLayout.NORTH);
- add(updateMemory, BorderLayout.SOUTH);
- }
- public static void main(final String[] args) throws
- InvocationTargetException, InterruptedException {
- final TestApplet applet = new TestApplet();
- EventQueue.invokeAndWait(new Runnable() {
- public void run() {
- applet.init();
- applet.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- applet.setSize(500, 200);
- applet.validate();
- applet.setVisible(true);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement