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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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