Results 1 to 9 of 9
- 10-28-2010, 03:35 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 28
- Rep Power
- 0
menubutton to activate a function
so i want to make this function to be inserted in my menu-button, "LäggTillKund"(which btw, is translated to new costumer).. anyway, i want public void läggtillkund to activate when i click läggtillkund-menubutton. i cant seem to figure out how
Java Code:import java.io.*; import javax.swing.*; import java.util.*; public class Kund { private String namn, efternamn, personnummer; private String Kundfil="Kunder.txt"; public void läggtillkund(String namn, String efternamn, String personnummer) throws IOException{ FileWriter x = new FileWriter(Kundfil, true); PrintWriter Y = new PrintWriter(x); namn=JOptionPane.showInputDialog("Ange nytt namn."); efternamn=JOptionPane.showInputDialog("Ange nytt efternamn."); personnummer=JOptionPane.showInputDialog("Ange nytt personnummer."); Y.print(""); Y.println(namn); Y.println(efternamn); Y.println(personnummer); Y.close(); }Java Code:import java.awt.*; import java.awt.event.*; import java.io.IOException; import javax.swing.*; public class Order extends JFrame{ private JMenuBar huvudmeny; private JMenu Profiler, Meny; private JMenuItem LäggTillKund, TagBortKund; private JComboBox box; private JPanel P, P2, P3; public Order(){ super("Huvudmeny"); huvudmeny = new JMenuBar(); Profiler = new JMenu("Profiler"); Meny = new JMenu("Meny"); LäggTillKund = new JMenuItem("Lägg till kund"); TagBortKund = new JMenuItem("Tag bort kund"); LäggTillKund.addActionListener(new LyssnareNYKUND()); TagBortKund.addActionListener(new Lyssnare2()); Profiler.add(LäggTillKund); Profiler.add(TagBortKund); setJMenuBar(huvudmeny); huvudmeny.add(Meny); Meny.add(Profiler); setSize(300, 300); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public class LyssnareNYKUND implements ActionListener{ public void actionPerformed(ActionEvent e){ if(e.getSource()==LäggTillKund) getContentPane().set Kund X = new Kund(); X.läggtillkund(); } } }
- 10-28-2010, 03:43 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
:eek:Java Code:if(e.getSource()==LäggTillKund) getContentPane().set Kund X = new Kund(); X.läggtillkund(); }
getContentPane().set <-- whats that and where is the brace to open the if-statement?
X.läggtillkund() : the method expected three parameter!
- 10-28-2010, 03:53 PM #3
- 10-28-2010, 04:17 PM #4
Member
- Join Date
- Sep 2010
- Posts
- 28
- Rep Power
- 0
- 10-28-2010, 04:18 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 28
- Rep Power
- 0
- 10-28-2010, 04:19 PM #6
We can't help you if you're not posting the actual code. I recommend you post an SSCCE based off the tutorial I linked and go from there.
- 10-28-2010, 04:28 PM #7
Member
- Join Date
- Sep 2010
- Posts
- 28
- Rep Power
- 0
alright, well check this out..
and the other class:Java Code:import java.io.*; import javax.swing.*; import java.util.*; public class Kund { private String namn, efternamn, personnummer; private String Kundfil="Kunder.txt"; public void läggtillkund(String namn, String efternamn, String personnummer) throws IOException{ FileWriter x = new FileWriter(Kundfil, true); PrintWriter Y = new PrintWriter(x); namn=JOptionPane.showInputDialog("Ange nytt namn."); efternamn=JOptionPane.showInputDialog("Ange nytt efternamn."); personnummer=JOptionPane.showInputDialog("Ange nytt personnummer."); Y.print(""); Y.println(namn); Y.println(efternamn); Y.println(personnummer); Y.close(); } public static void main (String[] args)throws IOException{ new Order(); } }
hope this make sense :)Java Code:import java.awt.*; import java.awt.event.*; import java.io.IOException; import javax.swing.*; public class Order extends JFrame{ private JMenuBar huvudmeny; private JMenu Profiler, Meny; private JMenuItem LäggTillKund; private JComboBox box; private JPanel P, P2, P3; public Order(){ super("Huvudmeny"); huvudmeny = new JMenuBar(); Profiler = new JMenu("Profiler"); Meny = new JMenu("Meny"); LäggTillKund = new JMenuItem("Lägg till kund"); LäggTillKund.addActionListener(new LyssnareNYKUND()); Profiler.add(LäggTillKund); setJMenuBar(huvudmeny); huvudmeny.add(Meny); Meny.add(Profiler); setSize(300, 300); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public class LyssnareNYKUND implements ActionListener{ public void actionPerformed(ActionEvent e){ //??? here, what to type to make the button work :( } } }
- 10-28-2010, 04:31 PM #8
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Last edited by eRaaaa; 10-28-2010 at 04:37 PM.
- 10-28-2010, 04:58 PM #9
Member
- Join Date
- Sep 2010
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Activate JComboBox 1 when object is selected in JComboBox 2...
By bahumbaba in forum AWT / SwingReplies: 2Last Post: 12-10-2009, 01:58 PM -
Does this function cause lag?
By Addez in forum New To JavaReplies: 5Last Post: 12-06-2009, 10:53 AM -
Possible? Callback function passed as arguments to another function
By TreyAU21 in forum Advanced JavaReplies: 3Last Post: 12-04-2009, 03:08 PM -
[SOLVED] MenuButton
By teo in forum New To JavaReplies: 5Last Post: 06-19-2008, 12:33 PM -
function name
By osval in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 08:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks