java画直线为什么不会显示 如何可以继续画直线
importjava.awt.BorderLayout;importjava.awt.Graphics;importjava.awt.Paint;importjava.a...
import java.awt.BorderLayout;import java.awt.Graphics;import java.awt.Paint;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;
import javax.swing.JFrame;import javax.swing.JPanel;
public class ku extends JFrame implements MouseListener{ int sx,sy,ex,ey;
public ku() { super("寂寞"); this.setBounds(100,100,700,700); this.setDefaultCloseOperation(EXIT_ON_CLOSE); aa b=new aa(); this.add(b); this.addMouseListener(this); this.setVisible(true); } public static void main(String[] args) { // TODO Auto-generated method stubnew ku(); }class aa extends JPanel{ public aa() {} public void paint(Graphics g) { g.drawLine(sx,sy,ex,ey); this.setVisible(true); }}public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub }public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub }public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub }public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub sx=e.getX(); sy=e.getY();}public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub ex=e.getX(); ey=e.getY(); }} 展开
import javax.swing.JFrame;import javax.swing.JPanel;
public class ku extends JFrame implements MouseListener{ int sx,sy,ex,ey;
public ku() { super("寂寞"); this.setBounds(100,100,700,700); this.setDefaultCloseOperation(EXIT_ON_CLOSE); aa b=new aa(); this.add(b); this.addMouseListener(this); this.setVisible(true); } public static void main(String[] args) { // TODO Auto-generated method stubnew ku(); }class aa extends JPanel{ public aa() {} public void paint(Graphics g) { g.drawLine(sx,sy,ex,ey); this.setVisible(true); }}public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub }public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub }public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub }public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub sx=e.getX(); sy=e.getY();}public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub ex=e.getX(); ey=e.getY(); }} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询