📄 getexceptiontimeframe.java
字号:
package getexceptiontime;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;import java.util.*;/** * <p>Title: getExceptionTime Demo</p> * <p>Description: This is a getExceptionTime demo</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: d6-125</p> * @author Liujun * @version 1.0 */public class getExceptionTimeFrame extends JFrame { JPanel contentPane; XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); //Construct the frame public getExceptionTimeFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(getExceptionTimeFrame.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(353, 163)); this.setTitle("get Exception Time Frame demo"); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(WindowEvent e) { this_windowOpened(e); } }); contentPane.add(jLabel2, new XYConstraints(21, 85, 302, 45)); contentPane.add(jLabel1, new XYConstraints(21, 36, 302, 45)); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void this_windowOpened(WindowEvent e) { int i = 0; int ntry = 1000000; Stack s = new Stack();//创建一个堆栈 long s1; long s2; s1 = new Date().getTime(); for (i = 0; i <= ntry; i++) if (!s.empty()) s.pop();//使用空栈检测方法 s2 = new Date().getTime(); //输出使用的时间 jLabel1.setText("测试空栈使用的时间:"+(s2 - s1) + " milliseconds"); s1 = new Date().getTime(); for (i = 0; i <= ntry; i++) { try { s.pop();//使用捕作违例方法 } catch(EmptyStackException ei) { } } s2 = new Date().getTime(); //输出使用的时间 jLabel2.setText("测试捕作空栈违例使用的时间:"+(s2 - s1) + " milliseconds"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -