First off, here is my code:
I am making a game and there are two problems that I have and can't seem to solve. I never made on applet before, and I'm not good with the swing components, but I am decent programming in Java.HTML Code:import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.border.Border; import javax.imageio.ImageIO; public class Main extends JApplet implements Runnable, ActionListener { private static final long serialVersionUID = 1L; private Thread thread = new Thread(this); private boolean running = true; private boolean laidOut = false; private int screenWidth = 500; private int screenHeight = 700; public Image jumper; public Image selectedJumper; public Image circle; public Image square; private JButton startButton; private JPanel panel; private JTable table; private JScrollPane scrollPane; public void init() { setSize(screenWidth, screenHeight); startButton = new JButton("Start"); startButton.addActionListener(this); getContentPane().add(startButton); circle = getImage(getCodeBase(), "http://www.javaprogrammingforums.com/images/Circle.png"); square = getImage(getCodeBase(), "http://www.javaprogrammingforums.com/images/Square.png"); panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); Border border = BorderFactory.createTitledBorder("Chose a jumper"); panel.setBorder(border); setLayout(new BorderLayout()); add(panel, BorderLayout.SOUTH); String columnNames[] = { "Circle", "Square" }; Image dataValues[][] = { { circle, square } }; table = new JTable( dataValues, columnNames ); scrollPane = new JScrollPane( table ); panel.add( scrollPane, BorderLayout.CENTER ); } public void start() { } public void destroy() { } public void stop() { } public void run() { } public void actionPerformed(ActionEvent e) { getContentPane().setBackground(Color.yellow); System.out.println("Button was clicked"); } public void paint(Graphics g) { if (!this.laidOut) { this.startButton.setSize(screenWidth/4, screenHeight/8); this.startButton.setLocation(screenWidth/2-(startButton.getWidth()/2), screenHeight/2); this.laidOut = true; } } }
Problem #1: the start button is in the JPanel, I don't want that, I want it to be above the JPanel.
Problem #2: I want to put images in to a JTable for organization and character selection purposes, but I keep on getting a string. Do I have to use an ImageIcon to get it to work, or does it matter?
In case you were wonder what kind of game I'm making, I'm making one of those jump games where you jump on platforms and try to go as high as you can without missing a platform. There is going to be character selection for the jumper, and the jumpers are going to be food, like a potato, a banana, a strawberry, etc. Once I get the game completed, I'm going to post to to GameJolt and make some money from ad revenue hopefully.
Any help would be great, thanks in advance.