Importing Images to a Java frame

  • Context: Java 
  • Thread starter Thread starter Quantum_Prodegy
  • Start date Start date
  • Tags Tags
    Frame Images Java
Click For Summary

Discussion Overview

The discussion revolves around how to import and set an image as the background of a Java frame in a simple Java program. Participants explore different methods and approaches for achieving this within the context of graphical user interface (GUI) programming in Java.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant suggests creating a Panel and using the drawImage method in its Graphics object.
  • Another participant proposes using a Canvas with an overridden paint() method or an ImageIcon.

Areas of Agreement / Disagreement

There are multiple competing views on how to implement the image background, with no consensus on a single approach being established.

Contextual Notes

Participants do not provide detailed explanations of the methods suggested, and there may be assumptions about the user's familiarity with Java GUI programming concepts.

Who May Find This Useful

Individuals interested in Java programming, particularly those working on GUI applications or seeking to enhance their understanding of image handling in Java.

Quantum_Prodegy
[SOLVED] Importing Images to a Java frame

Hey guys,

I have a very simple java program. I opens a frame, and I want to be able to put a picture in the frame. How do I import a picture and set it as the background to the frame?

Here is my simple program:

import java.io.*;
import java.awt.*;
import java.awt.event.*;

class demo extends Frame
{
void setup()
{
setLayout(new FlowLayout());

Button ok = new Button(" OK ");

add(ok);
}
}

public class window
{
public static void main (String[] args)
{
int width = 700, height = 134;

demo frm = new demo();

frm.setup();
frm.setBackground(Color.gray);
frm.setTitle("Logon Message");
frm.setSize(width, height);
frm.setVisible(true);
}
}

so as you can see it is an extremely basic window, and I would like to import a graphic as the background to the window within the setup() method.

Any help much appreciated, thanks!
-Jon
 
Technology news on Phys.org
somebody must know this
 
Create a Panel and call the drawImage method in its Graphics object.
 
Use a Canvas with an overridden paint() method, or an ImageIcon.

- Warren
 
:thumbsup: thanks guys
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K