java实际工作中的经验教训
来源:不详 责任编辑:admin 发表时间:2013-07-02 02:58 点击:次
我实际工作中的经验教训,在这里与大家共享,空的字符串是””,不带空格outputStream在打印时,打印的内容后面不要加\n,否则对方接受和判断不正确!
G:\PROJECTION\IC2N\1c2njava>javac Jsubnetframe.java
Jsubnetframe.java:22: Jsubnetframe should be declared abstract; it does not defi
ne valueChanged(javax.swing.event.ListSelectionEvent) in Jsubnetframe
public class Jsubnetframe extends JFrame implements ListSelectionListener {
^
Jsubnetframe.java:68: cannot resolve symbol
symbol : class TableModel
location: class Jsubnetframe
TableModel dataModel = new AbstractTableModel() {
^
Jsubnetframe.java:68: cannot resolve symbol
symbol : class AbstractTableModel
location: class Jsubnetframe
TableModel dataModel = new AbstractTableModel() {
^
Jsubnetframe.java:89: addActionListener(java.awt.event.ActionListener) in javax.
swing.AbstractButton cannot be applied to (Jsubnetframe)
cancelb.addActionListener(this);
^
Note: Jsubnetframe.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
4 errors
原因是没有import javax.swing.table.*;
G:\PROJECTION\IC2N\1c2njava>javac Jhpportframe.java Jhpportframe.java:27: Jhpportframe should be declared abstract; it does not defi ne mousePressed(java.awt.event.MouseEvent) in Jhpportframe public class Jhpportframe extends JFrame implements ^ Note: Jhpportframe.java uses or overrides a deprecated API. Note: Recompile with -deprecation for details. 1 error
Jhpportframe should be declared abstract; it does not define
原因是因为在这里必须用MouseListener 的相关方法进行覆盖,也就是说必须加入如下的方法:
public void mousePressed(MouseEvent evt) {//if (audio != null) audio.play();}
public void mouseEntered (MouseEvent me) {}
public void mouseExited (MouseEvent me) {}
public void mouseReleased(MouseEvent me) {}
鼠标左键和右件的事件获取:
public void mousePressed(MouseEvent evt) {
Point point1=evt.getPoint();
int x,y;
int onmask = evt.BUTTON1_DOWN_MASK;//左键的ID号
if ((evt.getModifiersEx() & onmask ) == onmask) // 点击左键时
{
}
else //点击右键时
抽象类,不能进行初始化或者生成实例
hpportimg=new Image(getDocumentBase(),”aaa.gif”);
这句话是错的,因为Image()是抽象类,不能进行初始化或者生成实例.,应该用:
hpportimg=getImage(“adf.gif”);
并且应该注意它不能放在构造函数中,而应该放在INIT()等方法中.
各种动作和事件的处理:
监视键盘的动作,用usertf.addKeyListener(this);
它的接口软件包是KeyListener,应该import java.awt.event.*;
必须重载的接口函数是
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
监视焦点的动作,用usertf.add FocusListener (this);
它的接口软件包是FocusListener应该import java.awt.event.*;
必须重载的接口函数是
public void focusLost(FocusEvent e) { }
public void focusGained(FocusEvent e) {}
监视鼠标的动作,用usertf.addMouseListener(this);
它的接口软件包是MouseyListener,应该import java.awt.event.*;
//必须增加MouseListener(this) 或component. MouseListener(this)
必须重载的接口函数是
public void mouseClicked(MouseEvent e){ }
public void mousePressed(MouseEvent evt) {}
public void mouseEntered (MouseEvent me) {}
public void mouseExited (MouseEvent me) {}
public void mouseR
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>






