• how to use a java image
    11 replies, posted
need some help to please include a java image in this [code]import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; import java.io.*; import javax.imageio.*; public class Main extends JPanel implements ActionListener { private JTextField textField; private JTextArea textArea; private JPanel panel; private static String newline = "\n"; public Main() { super(new GridBagLayout()); panel = new JPanel(); BufferedImage img = null; try { img = ImageIO.read(new File("logo.jpg")); } catch (IOException e) { } //add image to panel here textField = new JTextField(20); textField.addActionListener(this); textField.setFont(new Font("Agency FB", Font.PLAIN, 14)); textArea = new JTextArea(10, 20); textArea.setEditable(false); textArea.setLineWrap(true); textArea.setFont(new Font("Agency FB", Font.PLAIN, 14)); JScrollPane scrollPane = new JScrollPane(textArea); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; c.weighty = 1.0; add(panel, c); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 1.0; add(scrollPane, c); c.fill = GridBagConstraints.HORIZONTAL; add(textField, c); } public void actionPerformed(ActionEvent evt) { String text = textField.getText(); textArea.append("> "+text + newline); String[] command = text.split(" "); textField.selectAll(); textArea.setCaretPosition(textArea.getDocument().getLength()); } private static void initialise() { JFrame frame = new JFrame("Random Java Console"); frame.add(new Main()); frame.setResizable(false); frame.pack(); frame.setVisible(true); } @Override public void paintComponent(Graphics g) { } public static void main(String[] args) throws IOException, InterruptedException { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { initialise(); } }); } }[/code]
Your not adding the image to anything
i knw, cuz i dont know how to, i am asking for help -_-
Well what is it you want to do with the image?
i want to add and center the image above the textArea... [editline]04:30PM[/editline] you know what? FUCK YOU GUYS!!! its been here 2 hours and no help! So:[code]fuck you guys... i'm going home[/code]
addon, 3 hours now
Maybe you should learn some damn patience before you try learning Java.
It might take a couple of hours or a couple of days before anyone answers. Bumping doesn't help, really.
g.drawImage ?
Did he just give up?
He did. [editline]08:25AM[/editline] Apparently.
Golden thread.
Sorry, you need to Log In to post a reply to this thread.