Question: Java Graphics Programming

Ads

 
 
 

Share on Google+Share on Google+

deepakpuligundla
Java Graphics Programming
1 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners

Hi<BR> I am newbie to java and I have written a code in java that creates a window in which a line and rectangle appears. Here is the code.

import java.awt.*;<BR> public class FirstCanvase extends Canvas<BR> {<BR> public FirstCanvase()<BR> {<BR> setSize(500,500);<BR> setBackground(Color.white);<BR> }<BR> public static void main(String[] args) <BR> {<BR>

FirstCanvase FC=new FirstCanvase();<BR>

Frame f1=new Frame();<BR> f1.add(FC);<BR> f1.setSize(250,250);<BR> f1.setVisible(true);<BR> }<BR> public void paint(Graphics g)<BR> {<BR> g.setColor(Color.blue);<BR> g.drawLine(30,30,80,80);<BR> g.drawRect(50,50,100,100);<BR> }<BR> }<BR>

EVERY THING IS WORKING FINE. I GOT A WINDOW DISPLAYED WITH A LINE & RECT. BUT THE PROBLEM IS I AM UNABLE TO CLOSE THE WINDOW.

I AM USING ECLIPSE TO RUN THE PROGRAM.

WHAT CAN I DO TO SOLVE IT?

Ads
View Answers

July 23, 2012 at 12:27 PM


The given code draws a line and a rectangle on a swing frame using Graphics class.

 import javax.swing.*;
import java.awt.*;

public class DrawLineAndRectangle{
  public static void main(String[] args) {
  DrawLineAndRectangle d = new DrawLineAndRectangle();
  }

  public DrawLineAndRectangle(){
  JFrame frame = new JFrame("Drawing with Alpha");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().add(new MyComponent());
  frame.setSize(400,400);
  frame.setVisible(true);  
  }

  public class MyComponent extends JComponent{
  public void paint(Graphics g){
  int height = 200;
  int width = 120;
  g.setColor(Color.red);
  g.drawRect(10,10,180,100);

  g.setColor(Color.red);
  g.drawLine(250,50, 200,100);
  }
  }
}

Ads









Related Tutorials/Questions & Answers:
Java Graphics Programming
Java Graphics Programming  Hi<BR> I am newbie to java and I have written a code in java that creates a window in which a line and rectangle...;BR> public void paint(Graphics g)<BR> {<BR> g.setColor
java graphics
java graphics  Name three Component subclasses that support painting
Advertisements
graphics - Java Beginners
graphics  In java-graphics.. I want to draw a rectangle and resize that rectangle(small,big) ..by using mouse cursors
Java 2D Graphics - Applet
Java 2D Graphics  I am working on GIS project.I want represent a line in different forms like railroad, airplane etc. How can i acheive this I know...://www.roseindia.net/java/example/java/swing/graphics2D/ Here you will get lot
java 2d graphics - Java Beginners
java 2d graphics  Hello All I need to use 2d graphics in java to build up a map from the given geographic coordinates. What i am not getting is how to scale down these geographic coordinates to device coordinates. I would
How to draw in jPanel? swing/graphics Java
How to draw in jPanel? swing/graphics Java  How to draw in jPanel? (swing/graphics Java
java code along wid graphics design
java code along wid graphics design  actually i want to design nd make an apllication to solve a rubics cube of 3*3.. i have an algos wid me bt jus need ur guidance..plzz hlp out or if u have ny other ideas do suggest
java graphics - Design concepts & design patterns
java graphics  i dont wanna use Java3D but put solid 3D objects on screen, use z-buffering, ray-casting etc. to make realistic images...this will help build 3D fractals etc...Where must i begin reading
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
how to draw lines,circles, rectangles on JSP (using Java Graphics)
how to draw lines,circles, rectangles on JSP (using Java Graphics)  how to draw lines,circles, rectangles on JSP (using Java Graphics)   ... context Graphics g = image.getGraphics(); // Fill background g.setColor(Color.white
Java get Graphics
Java get Graphics     ... image.getGraphics() returns the Graphics object. The method...(400,400,BufferedImage.TYPE_INT_ARGB);   Graphics graphics=image.getGraphics
programming question - Java Magazine
programming question  I have an SGVT map displaying on a phone... Vector Graphics)which is XML based. SVGT(Scalable vector graphics tinny 1.1 )is one that mobile devices support. Map was drawn with IKIVO animator graphics
graphics program
graphics program  i want a program that implements merge sort algorithm in graphics
iPhone Graphics
iPhone Graphics  Hi, How to create iPhone Graphics? I am learning to crate UI Design for iPhone and iPad. Thanks
Java Programming
Java Programming  Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the student√?¬Ę√Ę‚??¬¨√Ę‚??¬Ęs programming mark. Determine how many student get A+ and A for their grade
Java programming
Java programming  What is the Role of OOP in java
Java programming
Java programming  What is the Role of OOP in java
java programming
java programming  Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the student‚??s programming mark. Determine how many student get A+ and A for their grade and how many
java programming
java programming  how to write a coding for simple login form in netbeans
programming - Java Beginners
programming for java beginners  How to start programming for java beginners
JAVA PROGRAMMING
JAVA PROGRAMMING  Write an OVERLOADED FUNCTION in java that swaps(interchanges) 2 user given numbers.(one integer and one float value) and displays the result after swapping. Invoke the function in a class
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
java programming
java programming  what is taxonomy tree why we use that concept in java   hierarchical taxonomy is a tree structure of classifications for a given set of objects
java programming
java programming  how to count the no. of constants in a user given string?? plzz help
FXG graphics
FXG graphics  Hi.... What is FXG in flex4? can you give me the explanation about it.. Thanks   Ans: FXG: FXG is a declarative syntax for defining static graphics. You typically use a graphics tool such as Adobe
java programming
java programming  Write a complete Java Program that correctly does the following: prints out first 1000 numbers (not including 1000) with a statement indicating whether it is even or not.. Output: Example Number 0 - Even
java programming
java programming  WAP to calculate the sum of: x + x(square)/2 + x(cube)/3 +.......... x(to the power n)/n
java programming
java programming  Hi friends, if i create one project what are the step i can make...... i need step by step procedure
java programming
java programming  supose i have a text field in java (like in gmail home page u have username field ) so i want to fill that field automatically by taking record from the database so is there any mechanism in java to handle
Tutorials   
Java Spring Hibernate Struts Training Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile? How to create first Java Program? Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include?

Ads

 
Advertisement null

Ads