I'm new to java, I started about 3 weeks ago. But I was making a program just for practice that lets you make HTML somewhat easy. The program isn't very useful but it gave me something to code. The only problem I was having was; whenever I ran the program the images didn't appear unless I put the full system path all the way from the drive. I wouldn't mind this but if I try running the program on another computer I have to go back and edit the code which isn't very cool when your trying to impress your parents. Well if anyone could help that would be awesome. Thanx in advance
My code:
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class StartingScreen extends JFrame {
String path = "F:/My Programs/Java/CreateHTML/EasyHTML/src/resources/Computing4Every1Logo.jpg";
String easyPath = "F:/My Programs/Java/CreateHTML/EasyHTML/src/resources/Easy_HTML_Logo.png";
ImageIcon img = new ImageIcon(path);
ImageIcon easyImg = new ImageIcon(easyPath);
int x = 0;
int y = 20;
int width = 30;
int height = 40;
Graphics g;
private static final long serialVersionUID = -7765334663035669163L;
public StartingScreen() {
super("image");
setSize(700,500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel top = new JPanel(new GridBagLayout());
JPanel middle = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(15,15,15,15);
JLabel label = new JLabel(img);
JLabel presents = new JLabel("Presents:");
JLabel label2 = new JLabel(easyImg);
gbc.gridx = 0;
gbc.gridy = 50;
top.add(presents, gbc);
gbc.gridx = 0;
gbc.gridy = 0;
top.add(label, gbc);
middle.add(label2, gbc);
add(middle, BorderLayout.CENTER);
add(top, BorderLayout.NORTH);
//menubar
JMenuBar j = new JMenuBar();
JMenu start = new JMenu("Start");
JMenu newHTML = new JMenu("New HTML");
JMenuItem menuScreen = new JMenuItem("Menu Screen");
JMenuItem insImg = new JMenuItem("Insert Image");
JMenuItem insTxt = new JMenuItem("Insert Text");
setJMenuBar(j);
j.add(start);
start.add(menuScreen);
start.add(newHTML);
newHTML.add(insImg);
newHTML.add(insTxt);
menuScreen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Menu a = new Menu();
a.setVisible(true);
dispose();
}
});
}
}