基本的に、それは表示されるようになっているので、テストして正しい方向に進んでいることを確認できます。これは私のメインの「電卓」ファイルのコードです。
package simplecalculator;
import javax.swing.JFrame;
import javax.swing.UIManager;
public class Calculator {
public static void main(String[] args) {
JFrame calculatorFrame = new Listener();
calculatorFrame.setSize(1000, 0x3e8);
calculatorFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
calculatorFrame.setVisible(true);
}
}
そして、クラス用に別のリスナーファイルがあります。
package simplecalculator;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Listener extends JFrame {
private JLabel enterFirstNumber;
private JLabel enterSecondNumber;
private JLabel resultLabel;
private JTextField getFirstNumber;
private JTextField getSecondNumber;
private JButton addition;
private JButton subtraction;
private JButton multiplication;
private JButton division;
private JPanel panelOne;
private JPanel panelTwo;
private JPanel panelThree;
private static final int frameWidth = 1000;
private static final int frameHeight = 1000;
int firstNumber;
int secondNumber;
double finalNumber;
public void Calc(){
setSize(frameWidth, frameHeight);
enterFirstNumber = new JLabel("Enter First Number: ");
getFirstNumber = new JTextField("0", 12);
enterSecondNumber = new JLabel("Enter Second Number: ");
getSecondNumber = new JTextField("0", 12);
}
public void buttons()
{
addition = new JButton("+");
addition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
firstNumber = Integer.parseInt(getFirstNumber.getText());
secondNumber = Integer.parseInt(getSecondNumber.getText());
finalNumber = firstNumber + secondNumber;
resultLabel.setText("" + finalNumber);
}
});
subtraction = new JButton("-");
subtraction.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
firstNumber = Integer.parseInt(getFirstNumber.getText());
secondNumber = Integer.parseInt(getSecondNumber.getText());
finalNumber = firstNumber - secondNumber;
resultLabel.setText("" + finalNumber);
}
});
multiplication = new JButton("*");
multiplication.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
firstNumber = Integer.parseInt(getFirstNumber.getText());
secondNumber = Integer.parseInt(getSecondNumber.getText());
finalNumber = firstNumber * secondNumber;
resultLabel.setText("" + finalNumber);
}
});
division = new JButton("/");
division.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
firstNumber = Integer.parseInt(getFirstNumber.getText());
secondNumber = Integer.parseInt(getSecondNumber.getText());
finalNumber = firstNumber / secondNumber;
resultLabel.setText("" + finalNumber);
}
});
}
private void panels(){
panelOne = new JPanel();
panelOne.setLayout(new GridLayout(2, 2));
panelOne.add(enterFirstNumber);
panelOne.add(getFirstNumber);
panelOne.add(enterSecondNumber);
panelOne.add(getSecondNumber);
panelTwo = new JPanel();
panelTwo.setLayout(new GridLayout(2, 2));
panelTwo.add(addition);
panelTwo.add(subtraction);
panelTwo.add(multiplication);
panelTwo.add(division);
panelThree = new JPanel();
panelThree.add(resultLabel);
}
}
基本的に私が知る必要があるのは:
1)私は正しい方向に進んでいますか?2)空白のアプレットではなく、実際の電卓を入手するにはどうすればよいですか?
初心者のように聞こえたらごめんなさい。私はprogramminの学生で、これを理解するためにすでに約12時間を費やしました。