?? structure.java
字號(hào):
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package lyric;import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;import java.util.*;/** * * @author 徐新坤 */public class Structure extends JPanel implements MouseListener,ActionListener{ public void actionPerformed(ActionEvent e) { System.out.println("action"); Time t = new Time(); if(e.getActionCommand().equals("START")){ t.start(); System.out.println("start"); } if(e.getActionCommand().equals("END")){ try{ t.stop(); time=0; } catch(Exception ex){ System.err.print(ex); } System.gc(); System.out.println("end"); } // throw new UnsupportedOperationException("Not supported yet."); } public void mouseClicked(MouseEvent e) { int minute = time / 6000; int second = time / 100 - minute * 60; int min = time - second * 100 - minute * 6000; String temp = "["+minute+":"+second+":"+min+"]"; int pos = GetPostion(e.getY()); InsertTime(temp,pos); System.out.println(temp);// throw new UnsupportedOperationException("Not supported yet."); } public void mouseEntered(MouseEvent e) {// throw new UnsupportedOperationException("Not supported yet."); } public void mouseExited(MouseEvent e) {// throw new UnsupportedOperationException("Not supported yet."); } public void mousePressed(MouseEvent e) {// int minute = time / 6000;// int second = time / 100 - minute * 60;// int min = time - second * 100 - minute * 6000;// String temp = "["+minute+":"+second+":"+min+"]";// System.out.println(temp);// throw new UnsupportedOperationException("Not supported yet."); } public void mouseReleased(MouseEvent e) {// throw new UnsupportedOperationException("Not supported yet."); } JTextArea jta; JButton jbs,jbe; ScrollPane sp; int time=0; public Structure(){ jta=new JTextArea(); jbs =new JButton("START"); jbe = new JButton("END"); sp = new ScrollPane(); setLayout(new BorderLayout()); add("Center",sp); sp.add(jta); add("East",jbe); add("West",jbs); jbs.addActionListener(this); jbe.addActionListener(this); jta.addMouseListener(this); } class Time { java.util.Timer ti=new java.util.Timer(); java.util.Date da=new java.util.Date(); public void start() { ti.scheduleAtFixedRate(new Task(),da,10); } public void stop() { ti.cancel(); } } class Task extends TimerTask { public void run(){ time++; } } private void InsertTime(String time,int position){ jta.insert(time, position); } private int GetPostion (int y){ int height =18;// jta.getRowHeight(); int line = y / height; int pos =0; try{ pos =jta.getLineStartOffset(line); System.out.println("y="+y+"h="+height); } catch(Exception ex){ System.err.println(ex); } return pos; }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -