progJ.pdf progJ-s.pdf progJ-e.pdf 記事一覧 |
カーソル位置の表示 (WinShot使用のためカーソルが枠外に移動) |
progJ.pdf の[#62]-[#63]に対応する部分を追加しました.
※ *.class は http://hakurei-isl.org/m-miyata/jar/App62-dist.zip,
http://hakurei-isl.org/m-miyata/jar/App63-dist.zip,
//App62.java
import java.awt.*;
import java.awt.event.*;
public class App62 extends App61 {
/* このように書くことが多いが構文が複雑.
App62( ){super( );
p1.addMouseMotionListener(new MouseAdapter( ){
public void mouseMoved(MouseEvent e){
tf1.setText(e.getX() +", "+ e.getY( ));
}
});
}
*/
//class MMA62 extends MouseMotionAdapter {
class MA62 extends MouseAdapter {
//MA62(){super(); /*追加なし*/}
public void mouseMoved(MouseEvent e){
tf1.setText(e.getX( ) +", "+ e.getY( ));
}
}
App62( ){super( );
p1.addMouseMotionListener(new MA62( ));
//p1.addMouseAdapter(new MA62( ));エラー
//p1.addMouseListener(new MMA62( ));無効
}
}
------------------------------------------
//App63.java
import java.awt.*;
import javax.swing.*;
class Fig61 extends JPanel{
Fig61( ){
super( );
setPreferredSize(new Dimension(300, 200));
setBackground(Color.white);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawLine(0,0,200,200);
g.drawString("Hello", 50, 150);
g.drawOval(150, 50, 100, 50);
int x = 90, y = 200, dx = 10, dy;
while(y <= 200){
dy = (-2 * (150 - x) * dx)/25;
g.drawLine(x, y, x + dx, y + dy);
x += dx; y += dy;
}//y = 56 - (150 - x)*(150 - x)/25
}
}
※コメント投稿者のブログIDはブログ作成者のみに通知されます