I'm kinda new at java, so how do I make this jframe display the graphics void?
import java.awt.Cursor;
import java.awt.Graphics;
import javax.swing.JFrame;
public class main {
public static String gameTitle = "Squares Mouse";
public static JFrame f = new JFrame(gameTitle);
public void paint(Graphics g){
g.drawString("Squares Mouse", 10, 20);
}
public static void createFrame(){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setCursor(Cursor.CROSSHAIR_CURSOR);
f.setSize(460, 340);
f.setVisible(true);
}
public static void main(String[] args) {
createFrame();
}
}thanks.
Offline
You need to extend from JFrame.
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
public class main extends JFrame{
public static String gameTitle = "Squares Mouse";
public main(){
setTitle(gameTitle);
setDefaultCloseOperation(3);
setCursor(Cursor.CROSSHAIR_CURSOR);
setSize(460, 340);
setVisible(true);
}
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D) g;
g2d.drawString("Squares Mouse", 10, 20);
}
public static void main(String[] args) {
new main();
}
}Last edited by poopo (2012-05-11 12:53:23)
Offline
poopo wrote:
You need to extend from JFrame.
well, still doesn't display it, but lets me add
main main = new main(); f.add(main);
Offline
poopo wrote:
try it now
I have no idea why it's not working.
still not working. I got this to work before, but i forget the code...
Offline
poopo wrote:
WindowsExplorer wrote:
poopo wrote:
try it now
I have no idea why it's not working.
still not working. I got this to work before, but i forget the code...
Check my last post.
![]()
can u just edit my code, and not completely change it to ur style of code, and add a new post, not edited. thanks
Offline
import java.awt.Cursor;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class main extends JPanel{
public static String gameTitle = "Squares Mouse";
public static JFrame f = new JFrame(gameTitle);
public void paint(Graphics g){
g.drawString("Squares Mouse", 0, 10);
}
public void createFrame(){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setCursor(Cursor.CROSSHAIR_CURSOR);
f.setSize(460, 340);
f.setVisible(true);
f.add(this);
}
public static void main(String[] args) {
new main().createFrame();
}
}That is the most like yours I can make it.
Offline
poopo wrote:
Code:
import java.awt.Cursor; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class main extends JPanel{ public static String gameTitle = "Squares Mouse"; public static JFrame f = new JFrame(gameTitle); public void paint(Graphics g){ g.drawString("Squares Mouse", 0, 10); } public void createFrame(){ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setCursor(Cursor.CROSSHAIR_CURSOR); f.setSize(460, 340); f.setVisible(true); f.add(this); } public static void main(String[] args) { new main().createFrame(); } }That is the most like yours I can make it.
Thanks
It works
!!!
Offline