11. november 2005 - 09:13
Der er
4 kommentarer og 1 løsning
Hjælp til applet
hej eksperter jeg har et stykke almindelige java kode der bliver kørt i komandopromt, jeg vil blot høre om ikke i kunne hjælp mig med at få det til at blive skrevet i en applet i stedet for, inge kanpper eller noget vildt bare i et applet vindue. her er min kode: import java.io.*; public class VisBeregninger extends JApplet { public static void main(String[] args) throws IOException { System.out.println("---====Velkommen til den statiske lommeregner===---"); System.out.println("Plus"); Beregninger minPlusBeregning = new Beregninger(); minPlusBeregning.intTal1 = 10; minPlusBeregning.intTal2 = 20; System.out.println( minPlusBeregning.beregnPlus()); System.out.println(" "); System.out.println("Minus"); Beregninger minMinusBeregning = new Beregninger(); minMinusBeregning.intTal1 = 50; minMinusBeregning.intTal2 = 20; System.out.println( minMinusBeregning.beregnMinus()); System.out.println(" "); System.out.println("Gange"); Beregninger minGangeBeregning = new Beregninger(); minGangeBeregning.intTal1 = 10; minGangeBeregning.intTal2 = 20; System.out.println( minGangeBeregning.beregnGange()); System.out.println(" "); System.out.println("Dele"); Beregninger minDeleBeregning = new Beregninger(); minDeleBeregning.intTal1 = 50; minDeleBeregning.intTal2 = 20; System.out.println( minDeleBeregning.beregnDele()); System.out.println(" "); System.out.println("---====Velkommen til den statiske lommeregner===---"); } }
Annonceindlæg fra Infor
11. november 2005 - 10:11
#1
import java.io.*; public class VisBeregninger extends JApplet { public void init() { System.out.println("---====Velkommen til den statiske lommeregner===---"); System.out.println("Plus"); Beregninger minPlusBeregning = new Beregninger(); minPlusBeregning.intTal1 = 10; minPlusBeregning.intTal2 = 20; System.out.println( minPlusBeregning.beregnPlus()); System.out.println(" "); System.out.println("Minus"); Beregninger minMinusBeregning = new Beregninger(); minMinusBeregning.intTal1 = 50; minMinusBeregning.intTal2 = 20; System.out.println( minMinusBeregning.beregnMinus()); System.out.println(" "); System.out.println("Gange"); Beregninger minGangeBeregning = new Beregninger(); minGangeBeregning.intTal1 = 10; minGangeBeregning.intTal2 = 20; System.out.println( minGangeBeregning.beregnGange()); System.out.println(" "); System.out.println("Dele"); Beregninger minDeleBeregning = new Beregninger(); minDeleBeregning.intTal1 = 50; minDeleBeregning.intTal2 = 20; System.out.println( minDeleBeregning.beregnDele()); System.out.println(" "); System.out.println("---====Velkommen til den statiske lommeregner===---"); } }
11. november 2005 - 21:14
#4
prøv den her: package november; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField; public class Calc extends JApplet implements ActionListener { private JTextField val; private JButton add; private JButton sub; private JButton mul; private JButton div; private JButton eql; private int acc; public Calc() { val = new JTextField(); add = new JButton("+"); add.addActionListener(this); sub = new JButton("-"); sub.addActionListener(this); mul = new JButton("*"); mul.addActionListener(this); div = new JButton("/"); div.addActionListener(this); eql = new JButton("="); eql.addActionListener(this); getContentPane().setLayout(new BorderLayout()); getContentPane().add(val, BorderLayout.NORTH); JPanel btns = new JPanel(); btns.setLayout(new GridLayout(3, 4)); btns.add(add); btns.add(sub); btns.add(mul); btns.add(div); btns.add(eql); getContentPane().add(btns, BorderLayout.CENTER); } public void init() { acc = 0; } public void actionPerformed(ActionEvent ev) { if(ev.getSource() == add) { acc += Integer.parseInt(val.getText()); val.setText(""); } else if(ev.getSource() == sub) { acc -= Integer.parseInt(val.getText()); val.setText(""); } else if(ev.getSource() == mul) { acc *= Integer.parseInt(val.getText()); val.setText(""); } else if(ev.getSource() == div) { acc /= Integer.parseInt(val.getText()); val.setText(""); } else if(ev.getSource() == eql) { val.setText(Integer.toString(acc)); acc = 0; } } }