Controlling and using the paintcomponent ( ) method

Assignment Help JAVA Programming
Reference no: EM13865137

What will you learn

-How to paint the screen -Controlling and using the paintComponent ( ) method

Deliverables

app.java, myJFrame.java, myJPanel.java,  and other necessary Java files

Recommended Java examples

The mouse motionexample The paintComponent example (image on a panel example) The how to use an array example (button array example) Drawingusing paintComponent

Contents

I am giving you a guide (try to start the work on the lab before consulting the guide). You have to create an application draws on the screen (Like MS-Paint) for instance.   The application has to: -draw lines as you drag the mouse -redraw what was on the screen when the screen is minimized and then maximized (or just resized)   When this is working then implement at least oneof the options below

  1. -let the user change the color of the lines
  2. -let the user choose a line thickness
  3. -an eraser

  Remember that the redrawing capability (in paintComponent) has to work with all the features. I mean, when the screen is resized, maximized, minimized, what was on the screen has to be redrawn.  

Lab 11 Guide

Drawing on the screen

There are many ways of drawing on the screen. In this lab the best solution is to fill small rectangles on the back of a Panel. You have to choose where to do this. The right place is the methodmouseDraggedthat is called every time the mouse is dragged.  

public void mouseDragged(MouseEvent evt)
{
   Point pt = evt.getPoint();
   int x = pt.x;
   int y = pt.y;
   Graphics gg = getGraphics();

   gg.setColor(Color.RED);
   gg.fillRect(x,y,5,5);

A reminder from the MouseListener lesson (Week 07)

Repainting the screen

Now that you are able to draw on the screen, try to resize it. You will note that the drawing disappeared. This is because what Java does is to give you a fresh back of the panel. It is your job to redraw whatever was there. To do this you need to follow a series of steps. 1.Save the original drawing. Since the drawing is a series of Xs and Ys (points), you need to save them. You can create an array of the type Point (Google "Java Point class"). 2.Every time the screen is resized, Java automatically calls the method paintComponent( ); You need to override (rewrite the original method) the original paintComponent method in the original JPanel class (remember, you are using a subclass of JPanel, one in which you can add (or override) methods and variables. If you haven't read the recommended reading on overriding, you should do so now. 3.In the new paintComponent ( ) method, you will read the points you saved and ask them to be redrawn.   

Reference no: EM13865137

Questions Cloud

Relationship between sales calls and sales dialogue : Which of the following best reflects the relationship between sales calls and sales dialogue
Asymmetric shocks dealt with within a country : How are asymmetric shocks dealt with within a country? To what extent can this process be mirrored within the Eurozone?
About publically traded health care organizations : publically traded health care organizations
Describes common reason why salespeople dislike prospecting : Which of the following describes a common reason why salespeople dislike prospecting
Controlling and using the paintcomponent ( ) method : How to paint the screen -Controlling and using the paintComponent ( ) method Deliverables app.java, myJFrame.java, myJPanel.java,  and other necessary Java files
Write a function called makemat that will receive two row : Write a function called makemat that will receive two row vectors as input arguments, and from them create and return a matrix with two rows.
Effect of the watchs destruction on the parties : Explain how UCC Art. 2 would apply to these facts from the perspectives of A, B, C and D in terms of The legal relationships between A and B, A and C, B and C, and C and D;
Determine the sources of credit available : Determine the sources of credit available (where can you get credit, advantages and disadvantages of the types).
The world benefit from the general imposition of controls : Would the world benefit from the general imposition of controls on the movement of international finance?

Reviews

Write a Review

JAVA Programming Questions & Answers

  The game of pig

Write a program that allows a single player to practice the game (that is, there will be no opponent, just a single player). Play 5 turns in the game to get a total score for the player. Refer to the sample output below for a detailed example.

  Draw a picture with an appearance

You must use the given Rectangle and Oval classes to draw a picture with an appearance as close as possible.

  Create a class diagram that shows an interface

Create a class diagram that shows an interface called Buyer in the Violet UML editor. This interface should declare the methods to perform a buyer's responsibilities

  Part-1prepare a program that teaches arithmetic to a young

part-1prepare a program that teaches arithmetic to a young child. the program tests subtraction and addition. in level

  Object from question 1 manage its display

Write a Java statement to have the object from question 1 manage its display area by dividing it into 3 rows which have 4 columns each.

  Give at least one constructor without any parameter

We learned as popular Set implementation. Write own TreeSet class that implements following interface: You are to give at least one constructor without any parameter.

  Write a program to find solution tocryparithmetic puzzle

Write a program (Crypta.java) that finds a solution to the cryparithmetic puzzle: TOO + TOO + TOO+ TOO = GOOD

  Design a class that you can use to track the books

Define a class PileOfBooks that implements the interface described in question one. use a resizeable array oin your implementation. then write unit test woth adequate test cases for your implementation of class PiloOfBooks.

  Java''s type int has limit onhow large aninteger it can store

Java's type int has a limit on how large an integer it can store. This limit can be circumvented by representing an integer as an array of digits. Write an interactive program that adds two integers of up to 50 digits each.

  Build an android application to execute some of the queries

Build an android application to execute some of the queries -

  Write down a java program which prints out division by zero

write a java program that prints out division by zero and array out of bounds exceptions when a user attempts to find

  Your task in this assignment is to develop a graphical user

your task in this assignment is to develop a graphical user interface based java program that can communicate with a

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd