如何实现鼠标推动过过程中的虚线选取框 如何实现鼠标推动过过程中的虚线选取框 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.swing.* ;import java.awt.* ;import java.awt.event.* ;public class testMove extends JFrame { int x1 = 0 ; int y1 = 0 ; int x2 = 0 ; int y2 = 0 ; boolean flag = false ; testMove() { this.setSize( 400,300 ) ; this.addMouseMotionListener( new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { if( flag ) { x2 = e.getX() ; y2 = e.getY() ; repaint() ; } } }) ; this.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { if( !flag ) { flag = true ; x1 = e.getX() ; y1 = e.getY() ; } } public void mouseReleased(MouseEvent e) { flag = false ; } }) ; this.setVisible( true ) ; } public void paint( Graphics g) { super.paint( g ) ; Graphics2D g2 = (Graphics2D) g; BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[]{10.0f,5.0f}, 0.0f); g2.setStroke(dashed); g.drawRect( this.x1, this.y1, this.x2-this.x1, this.y2-this.y1 ) ; } public static void main( String args[] ) { new testMove() ; }}是不是这个意思?没判断鼠标移动方向 小弟领教了。小弟才学GUI不是很懂。谢谢 关于java多线程的一个异常IllegalMonitorStateException 散分了 关于main方法 ARP拓扑检测 求算法一种 请问哪个高手帮我解释一下代码 JSP中文显示的问题 Vector能不能定义类似多维的数组的东西,谢谢. 卸装norton2002后为什么我的win2000里看不到装的软件了? 怎样求出一个日期对应的星期几(DAY_OF_WEEK)啊? 使用IO流读取Socket服务器数据时,当数据较大(几十K字节)时为什么读不全,在线等待---谢谢 关于包,求助~~~~
import java.awt.* ;
import java.awt.event.* ;public class testMove extends JFrame
{
int x1 = 0 ;
int y1 = 0 ;
int x2 = 0 ;
int y2 = 0 ;
boolean flag = false ;
testMove()
{
this.setSize( 400,300 ) ;
this.addMouseMotionListener( new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e)
{
if( flag )
{
x2 = e.getX() ;
y2 = e.getY() ;
repaint() ;
}
}
}) ;
this.addMouseListener( new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
if( !flag )
{
flag = true ;
x1 = e.getX() ;
y1 = e.getY() ;
}
}
public void mouseReleased(MouseEvent e)
{
flag = false ;
}
}) ;
this.setVisible( true ) ;
}
public void paint( Graphics g)
{
super.paint( g ) ;
Graphics2D g2 = (Graphics2D) g;
BasicStroke dashed = new BasicStroke(1.0f,
BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER,
10.0f,
new float[]{10.0f,5.0f},
0.0f);
g2.setStroke(dashed);
g.drawRect( this.x1, this.y1, this.x2-this.x1, this.y2-this.y1 ) ;
}
public static void main( String args[] )
{
new testMove() ;
}
}是不是这个意思?没判断鼠标移动方向