Alright here's what I'm trying to do. I'm making a item drop logger for an MMO I play. The goal of the program is for the user to be able to click the image of the drop they got (button) and have the button write the drop into a text file. So far I have 2 seperate codes that I can't figure out how to combine. I'm also trying to figure out how to put an if statement into the writter file.
Writter code:
import java.io.*; import javax.swing.JOptionPane; public class logger { Writer output = null; String text = "Dragon Hatchet"; File file = new File("Dagannoth Droplog.txt"); output = new BufferedWriter(new FileWriter(file)); output.write(text); output.close(); } }
Button code:
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.awt.Toolkit; import java.io.*; public class SwingButtonDemo { public static void main(String[] a) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new ButtonDemo()); f.setSize(550, 400); f.setVisible(true); } } class ButtonDemo extends JPanel implements ActionListener { JTextField jtf; public ButtonDemo() { try { makeGUI(); } catch (Exception exc) { System.out.println("Can't create because of " + exc); } } private void makeGUI() { setLayout(new FlowLayout()); ImageIcon DragonHatchet = new ImageIcon( "C:/Users/Jackson/Desktop/Dragon_hatchet.gif"); JButton jb = new JButton(DragonHatchet); jb.setActionCommand("Dragon Hatchet"); jb.addActionListener(this); add(jb); ImageIcon BerserkerRing = new ImageIcon( "C:/Users/Jackson/Desktop/Berserker_ring_(i).gif"); jb = new JButton(BerserkerRing); jb.setActionCommand("Berserker Ring"); jb.addActionListener(this); add(jb); ImageIcon WarriorRing = new ImageIcon( "C:/Users/Jackson/Desktop/Warrior_Ring.gif"); jb = new JButton(WarriorRing); jb.setActionCommand("Warrior Ring"); jb.addActionListener(this); add(jb); ImageIcon EliteClue = new ImageIcon("C:/Users/Jackson/Desktop/Clue_scroll.gif"); jb = new JButton(EliteClue); jb.setActionCommand("Elite Clue Scroll"); jb.addActionListener(this); add(jb); jtf = new JTextField(15); add(jtf); ImageIcon ii=new ImageIcon("C:/Users/Jackson/Desktop/droplogger.png"); JLabel label=new JLabel(ii); label = new JLabel("Dragon Hatchet"); } public void actionPerformed(ActionEvent ae) { jtf.setText(ae.getActionCommand()); } }
If anyone could tell me how I could incorporate the two codes into one that would be awesome.
Also, to avoid making another topic: How would I write and if then statement to tell the difference between the drops? An example would be
if (user clicks dragon hatchet image)
then log "1x dragon hatchet" to droplog.txt


LinkBack URL
About LinkBacks
Reply With Quote