I have looked this up and cant seem to find a solution. Nothing I can find will work with my code. I really need help because i am doing this for a class project and nothing will work.

Heres what i'm trying to get it to work with.

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class enterNames extends JFrame {

	public static JFrame page2 = new enterNames();

	public enterNames() {

	}

	enterNames(String st) {

		Scanner s = new Scanner(System.in);
		setLayout(null);
		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("Enter Names");
		JLabel a1 = new JLabel("Player 1 Enter Name:");
		a1.setBounds(50, 50, 400, 30);
		JLabel a2 = new JLabel("Player 2 Enter Name:");
		a2.setBounds(50, 150, 400, 30);

		JTextField t1 = new JTextField("Enter here...");
		t1.setBounds(50, 100, 400, 30);
		t1.setBackground(new Color(124, 242, 0));

		JTextField t2 = new JTextField("Enter here...");
		t2.setBounds(50, 200, 400, 30);
		t2.setBackground(new Color(124, 242, 0));

		JButton b1 = new JButton("Submit");
		b1.setBounds(50, 300, 400, 30);
		b1.setBackground(new Color(124, 242, 0));
		b1.setForeground(new Color(0, 191, 255));
		
		add(a1);
		add(a2);
		add(t1);
		add(t2);
		add(b1);
		setSize(500, 500);

		SubmitListener s1 = new SubmitListener();
		b1.addActionListener(s1);

	}

	public static void main(String[] args) {
		page2.setBackground(Color.gray);
		page2.setTitle("Skate Dice");
		page2.setSize(500, 500);
		page2.setLocationRelativeTo(null);
		page2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		page2.setVisible(true);
	}

	class SubmitListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
													
			openChoose();

		}
	}

	private void openChoose() {

		page2.setVisible(false);
		choose page3 = new choose(null);
		page3.setVisible(true);
		page3.setLocationRelativeTo(null);
		page3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

		
	}
}

Where does the code get the image from?
Where do you want to show the image?

Why are you using the Scanner class?

Where does the code get the image from?
Where do you want to show the image?

Why are you using the Scanner class?

The code gets the image will get my the image from my hard drive. I want to show the image as the background. The scanner class was the only thing i could use to get my code to work because i have multiple frames all tied together. If i used a jpanel nothing would show up.

Where is the code you are having problems with?
I don't see any code that tries to read an image or that tries to show an image?

Where is the code you are having problems with?
I don't see any code that tries to read an image or that tries to show an image?

i need to know where to put it and if it will work ive tried putting it in the enterNames(String st) but i keep getting squiggled.

where to put it and if it will work

What is the "it" you are talking about?
If you have the name of the image file you could read its contents in the class's constructor.
Where are you going to display the image? In a JLabel? Or draw it yourself in a JPanel?

i keep getting squiggled.

Can you explain?
If you get error messages, copy and paste them here.

What is the "it" you are talking about?
If you have the name of the image file you could read its contents in the class's constructor.
Where are you going to display the image? In a JLabel? Or draw it yourself in a JPanel?

ImageIcon img11 = new ImageIcon("skatebackground.jpg");
Image image11 = img1.getImage();
add(image11, 100, 100);


thats what im trying to do in the enterNames(String st).id like to draw it as a jlabel, but i have no clue how.

Can you explain?
If you get error messages, copy and paste them here.

the error message i get is at add(image11, 100, 100). it squiggles the add and it says

The method add(Component, int) in the type Container is not applicable for the arguments (Image, int, int)

add(Component, int) in the type Container is not applicable for the arguments (Image, int, int)

You need to read the API doc for the add method. The compiler wants there to be an object of type Component, you have coded an object of type Image. The Image class does not extend the Component class.

Have you tried putting the image as an icon into a JLabel and adding the JLabel (which extends Component)?

You need to read the API doc for the add method. The compiler wants there to be an object of type Component, you have coded an object of type Image. The Image class does not extend the Component class.

Where do i find the api doc?

Have you tried putting the image as an icon into a JLabel and adding the JLabel (which extends Component)?

No i have not. How would i go about doing this?

I still dont get how to enter it.

Please explain what your problem is.

Create an ImageIcon
Create a JLabel using that ImageIcon
Add the JLabel to the frame

Please explain what your problem is.

Create an ImageIcon
Create a JLabel using that ImageIcon
Add the JLabel to the frame

Ok I created the ImageIcon now how do i tie it to the JLabel?

It is shown in the API doc for the JLabel class.

The ImageIcon class implements the Icon interface.

It is shown in the API doc for the JLabel class.

The ImageIcon class implements the Icon interface.

I got it, thank you. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.