Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2012, 08:11 PM   PM User | #1
<Tensor>
New to the CF scene

 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
<Tensor> is an unknown quantity at this point
Basic GUI question-Jframes and JPanels

Hello everyone,

I'm brand new to coding, and I have a small GUI question. I want to open a JFrame that fills the computer screen initially and that holds a JPanel that fills the entire JFrame. Further, I want this JPanel to hold a graphic JPG file that I have downloaded. Basically, I want a JFrame that is completely filled with "wallpaper". I have found the proper classes and methods to accomplish this and have coded properly. However, the wallpaper graphic only fills the upper left corner of the JFrame window and not the entire window. How do I reach my goal?

Here is my attempt at a code. Please, offer any suggestions that come to mind:

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;


public class lexicon extends JFrame
{

public lexicon (String str)
{
super (str);
}
private void process()
{
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(0,0);
this.setSize(dim.width, dim.height);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String [] args)
{
lexicon frame = new lexicon("Lexicon");
frame.process();
panel dragon = new panel();
dragon.setMaximumSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.setContentPane(dragon);

}

public static class panel extends JPanel
{
public panel()
{
super();
}

BufferedImage image;

public void paintComponent(Graphics g)
{
try
{

image = ImageIO.read(new File("C:\\Users\\Urban\\Desktop\\Chinese Dragon.jpg"));
}
catch (Exception ex)
{
}

g.drawImage(image, 0, 0, null);
}
}
}
<Tensor> is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:52 AM.


Advertisement
Log in to turn off these ads.