|
||
|
|||
|
Hello all, i've just started java and i'm really not good at it, i've read about JPanel JFrame and the different layouts I can use and I still can't get my head round to setting an image as background with two simple buttons on top, I've tried every single combination I could think and have googled for ages, nothing seems to work... here is my code:
Java Code
import javax.swing.*;
import java.awt.*;
class Intro implements Runnable
{
public static void main(String[] args)
{
Intro program = new Intro();
SwingUtilities.invokeLater(program);
}
public void run()
{
JFrame inicio = new JFrame("Videogame");
inicio.setLayout(new BorderLayout());
JPanel bt = new JPanel();
ImageIcon image = new ImageIcon("image.jpg");
bt.add(new JButton("START"));
bt.add(new JButton("QUIT"));
inicio.add(new JLabel(image));
inicio.add(bt, BorderLayout.SOUTH);
inicio.setDefaultCloseOperation(inicio.EXIT_ON_CLOSE);
inicio.setSize(800,600);
inicio.setLocationByPlatform(true);
inicio.setVisible(true);
}
}
Thanks!
Last edited by OBLITERATOR; 05-03-2010 at 12:30 AM. Reason: Edited to make code more visible |
|
|||
|
Java Code
import javax.swing.*;
import java.awt.*;
class Intro implements Runnable
{
public static void main(String[] args)
{
Intro program = new Intro();
SwingUtilities.invokeLater(program);
}
public void run()
{
JFrame inicio = new JFrame("Videogame");
inicio.setDefaultCloseOperation(inicio.EXIT_ON_CLOSE);
inicio.setSize(800,600);
inicio.setLocationByPlatform(true);
inicio.setVisible(true);
JPanel bt = new JPanel();
bt.add(new JButton("START"));
bt.add(new JButton("QUIT"));
JPanel over = new JPanel();
LayoutManager overlay = new OverlayLayout(over);
over.setLayout(overlay);
JPanel imagen = new JPanel();
ImageIcon image = new ImageIcon("image.jpg");
imagen.add(new JLabel(image));
over.add(imagen);
over.add(bt);
inicio.add(over);
}
}
It works fine except the second (QUIT) button takes a while to load and I don't understand why... any ideas? Sorry for the bother! |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| JButton set background problem | ellias2007 | AWT / Java Swing | 1 | 25-02-2010 04:15 AM |
| Array to image | oxxxis | Collections and Generics | 1 | 19-01-2010 10:46 PM |
| Pixel Alteration in an image/image rotation | bguy | Java Theory & Questions | 3 | 01-11-2009 02:50 PM |
| RGB - YUV - awt.Image | BharatT | AWT / Java Swing | 0 | 24-02-2009 09:10 AM |
| How to Import an Image in JSP? | jazz2k8 | JavaServer Pages: JSP & JSTL | 4 | 12-05-2008 10:55 AM |
|
100 most searched terms
Search Cloud
|
| 2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? |