Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm using the Console class in Holtsoft's Ready To Program Java for this. I'm not allowed to use javax.swing or make this an applet.

I don't know how to make the program, but need to make it:
a) Run only in the console window or
b) Make the Frame window hidden, but still functional

Java
import java.awt.event.*;
import java.awt.*;
import hsa.*;

public class MouseTest extends Frame
{
    int startX, startY, endX, endY;
    Console c = new Console ();
    public MouseTest ()
    {
        super ();

        MouseListener start = new MouseListener ()
        {
            public void mouseClicked (MouseEvent e)
            {
            }

            public void mouseEntered (MouseEvent e)
            {
            }

            public void mouseExited (MouseEvent e)
            {
            }

            public void mousePressed (MouseEvent e)
            {
                startX = endX = e.getX ();
                startY = endY = e.getY ();
                repaint ();
            }

            public void mouseReleased (MouseEvent e)
            {
            }
        }
        ;
        addMouseListener (start);

        MouseMotionListener end = new MouseMotionListener ()
        {
            public void mouseDragged (MouseEvent e)
            {
                endX = e.getX ();
                endY = e.getY ();
                repaint ();
            }

            public void mouseMoved (MouseEvent e)
            {
            }
        }
        ;
        addMouseMotionListener (end);

    }


    public void paint (Graphics g)
    {
        super.paint (g);
        c.clear ();
        c.setColor (Color.black);
        c.drawLine (startX, startY, endX, endY);
    }


    public static void main (String args[])
    {
        Frame frame = new MouseTest ();
        frame.setLocation (950, 100);
        frame.setSize (400, 400);
        frame.enable ();
        frame.show ();

    }
}
Posted

1 solution

What would be the benefit of not having a visible Frame?

Anyway, you can set the Frame setVisible(false)

To see some console output you use System.out.println("creativetext")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900