I have been trying to make a java graphics program but whenever i try to make it work nothing happens, no window appears. Here is my source code:
import java.awt.*;
public class graphics {
public static void main(String args[]){
}
public void paint(Graphics g){
g.drawRect(300, 200, 75, 75);
}
}
p.s. the reason i have a public static void main without anything in it is because otherwise when i run it, it says i need to have a public static void main(String args[]) in it.
11 2246 public static void main(String[] args) is the main method - the program does, what this function tells it to do. So if you just change it like this: -
public static void main(String args[]){
-
paint(graphic); // "graphic" being, what ever should be drawn
-
}
-
you should at least get some reaction. However, I haven't used awt yet, so I don't know, if that will be your problem solved.
I have been trying to make a java graphics program but whenever i try to make it work nothing happens, no window appears. Here is my source code:
import java.awt.*;
public class graphics {
public static void main(String args[]){
}
public void paint(Graphics g){
g.drawRect(300, 200, 75, 75);
}
}
p.s. the reason i have a public static void main without anything in it is because otherwise when i run it, it says i need to have a public static void main(String args[]) in it.
OK. Um, you need to be painting somewhere you see. Now you don't paint to the console like that. Read Sun's painting tutorial to see how it's done.
Does that mean that i should place the public void paint(Graphics g) should be within the public static void main
Does that mean that i should place the public void paint(Graphics g) should be within the public static void main
All that stuff is wrong. See my reply above.
Does that mean that i should place the public void paint(Graphics g) should be within the public static void main
You will have to use the public static void main at some point, but as r035198x pointed out, there are other things to be done too.
I have been trying to make a java graphics program but whenever i try to make it work nothing happens, no window appears. Here is my source code:
import java.awt.*;
public class graphics {
public static void main(String args[]){
}
public void paint(Graphics g){
g.drawRect(300, 200, 75, 75);
}
}
p.s. the reason i have a public static void main without anything in it is because otherwise when i run it, it says i need to have a public static void main(String args[]) in it.
The JVM invokes your public static void main(String[] args) allright, but that
method is just empty so it doesn't do anything. Who or what do you expect to
invoke that public void paint(Graphics g) method? Only AWT Components
or Swing JComponents have that method invoked when needed, but you
don't have any of those. Please read a Swing/AWT tutorial before you expect
automagic things to happen.
kind regards,
Jos
The JVM invokes your public static void main(String[] args) allright, but that
method is just empty so it doesn't do anything. Who or what do you expect to
invoke that public void paint(Graphics g) method? Only AWT Components
or Swing JComponents have that method invoked when needed, but you
don't have any of those. Please read a Swing/AWT tutorial before you expect
automagic things to happen.
kind regards,
Jos
There's no such word as automagic.
There's no such word as automagic.
Yes there is; you just saw it so it exists. It even associates with quite a lot of
other things so it's an existing, semantically rich word; it can even be a noun.
automagically yours,
Jos ;-)
I have been trying to make a java graphics program but whenever i try to make it work nothing happens, no window appears. Here is my source code:
import java.awt.*;
public class graphics {
public static void main(String args[]){
}
public void paint(Graphics g){
g.drawRect(300, 200, 75, 75);
}
}
p.s. the reason i have a public static void main without anything in it is because otherwise when i run it, it says i need to have a public static void main(String args[]) in it.
Hi
I think you are not aware that what is your problem. Better Read Applets that will be good for the better understanding of your program.
I can make the window appear but nothing appears on it. This is my code: - import java.awt.Graphics;
-
-
import javax.swing.SwingUtilities;
-
import javax.swing.JFrame;
-
-
public class graphicsprogram {
-
-
public static void main(String[] args) {
-
SwingUtilities.invokeLater(new Runnable() {
-
public void run() {
-
createAndShowGUI();
-
}
-
});
-
}
-
-
public void paint(Graphics g){
-
g.drawRect(100,100,75,75);
-
}
-
private static void createAndShowGUI() {
-
JFrame f = new JFrame("graphics program");
-
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
f.setSize(250, 250);
-
f.setVisible(true);
-
}
-
}
I can make the window appear but nothing appears on it. This is my code: - import java.awt.Graphics;
-
-
import javax.swing.SwingUtilities;
-
import javax.swing.JFrame;
-
-
public class graphicsprogram {
-
-
public static void main(String[] args) {
-
SwingUtilities.invokeLater(new Runnable() {
-
public void run() {
-
createAndShowGUI();
-
}
-
});
-
}
-
-
public void paint(Graphics g){
-
g.drawRect(100,100,75,75);
-
}
-
private static void createAndShowGUI() {
-
JFrame f = new JFrame("graphics program");
-
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
f.setSize(250, 250);
-
f.setVisible(true);
-
}
-
}
See what they used for a drawing surface in this example.
You really need to go through that tutorial before you start writing some code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: SamSpade |
last post by:
Public Function PicCreateGraphics() As Graphics
'Client should dispose this
PicCreateGraphics = Graphics.FromImage(mDocumentImage)
mPicCreateGraphicsSaved = PicCreateGraphics 'Saved so I can...
|
by: Nathan Sokalski |
last post by:
I am trying to write code to rotate a graphic that I have. Here is the code
I am currently using:
Dim frogbitmap As New
Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif")))
Dim...
|
by: Nathan Sokalski |
last post by:
I am trying to write code to rotate a graphic that I have. Here is the code
I am currently using:
Dim frogbitmap As New
Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif")))
Dim...
|
by: IvoShalev |
last post by:
Hi there,
I just want to give some sudgestions on how to draw some plain things
only using the header file <graphics.hand of course the standart
files <stdio.h<conio.h<stdlib.h>.
First of All...
|
by: Anil Gupte |
last post by:
I copied the following almost directly from
http://msdn2.microsoft.com/en-us/library/6xe5hazb.aspx
Dim instance As Graphics
Dim text As String
'Dim strfont As Font
Dim returnValue As...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |