• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set the window background image, include multiple buttons, and add text  RSS feed

 
Adan Ramirez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello great community, thanks for taking the time to look at this post i hope i dont offend any developers of my amateurness but im in deep trouble, im trying to set an image for my app and have some buttons that run things like opening a url, etc. simple stuff, then adding some text to it to describe the buttons, however, as im learning how to add buttons, then add images, i cannot blend them or combine them together, it seems that every time i find a solution for a piece of my app, it's incompatible with another, but enough of my rambles, let me show you the code im running:

package x(name of my package);

import javax.swing.*;
import java.awt.*;

class x(name of my class) extends JFrame

{

private static final long serialVersionUID = 1L;

JButton b1;
JLabel l1;

public button()
{
setTitle("Background Color for JFrame");
setSize(1440,1080);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);

setLayout(new BorderLayout());
setContentPane(new JLabel(new ImageIcon("C:\\Users\\x(name of computer)\\Downloads\\helena.jpg")
setLayout(new FlowLayout());
l1=new JLabel("here is a button");
b1=new JButton("I am a button");
add(l1);
add(b1);
setSize(1,1);
setSize(1440,,1080);

}

public static void main(String[] args){

new button();
}

}

/* Running this yields background image along with my buttons, however when trying to implement this code for some text on the background image, i get a bunch of errors and so my question is... with this code, how do i implement text ontop of the background image? How do i make my buttons run things? how do i customize my buttons with images?

**code:
Graphics g = image.getGraphics();
g.setFont(g.getFont().deriveFont(30f));
g.drawString("Hello World!", 100, 100);
g.dispose();

i appreciate all the help and thanks!
*/
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Adan, and welcome to the Ranch! You have so much to learn that I really don't know where to start, so I'll refer you to the Oracle tutorials: Trail: Creating a GUI With JFC/Swing where you can find the answers to all your questions.

A few notes:
  • By convention, Java class names start with an uppercase letter.
  • Components should be added to a top level window before, not after it is made visible.
  • UseCodeTags (<- link) when posting code.
  • PostRealCode (<- link) not code with typos like setSize(1440,,1080);
  • When seeking help with errors, post the entire error text or stack trace; that makes it easier to identify the source of the problem.


  • Do work your way through the tutorial and come back when you have a specific question about any part of it.
     
    Darryl Burke
    Bartender
    Posts: 5167
    11
    Java Netbeans IDE Opera
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    One more: please BeForthrightWhenCrossPostingToOtherSites
    http://www.java-forums.org/new-java/94802-how-set-window-background-image-include-multiple-buttons-add-text.html
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!