R
R
Rudy99662021-09-18 23:59:18
Java
Rudy9966, 2021-09-18 23:59:18

How to make several with one variable or how to parse one variable?

The bottom line is that now I work with swing. At the moment there is a text field in which grades are entered.
I need to separate these scores into different variables in order to transfer them to another point system in the future. I thought to do it like with a scanner through useDelimiter, but it doesn’t work there (How can I do this?

package lab2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;


public class main extends JFrame {
  private JButton button = new JButton("Press");
  private JTextField input = new JTextField("60 75 90 100", 5);
  private JLabel label = new JLabel("Input:");
  private JRadioButton radio1 = new JRadioButton("Budget");
  private JRadioButton radio2 = new JRadioButton("ne budget");
  private JCheckBox check = new JCheckBox("Check", false);
  
  public main() {
    super("Simple Example");
    this.setBounds(100, 100, 250, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    Container container = this.getContentPane();
    container.setLayout(new GridLayout(3,2,2, 2));
    container.add(label);
    container.add(input);
    
    ButtonGroup group = new ButtonGroup();
    group.add(radio1);
    group.add(radio2);
    container.add(radio1);
    radio1.setSelected(true);
    container.add(radio2);
    container.add(check);
    
    button.addActionListener(new ButtonEventListener());
    container.add(button);
    
  }
  
  class ButtonEventListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      String message = "";			
      message += "Button was pressen\n";
      message +="Text is" + input.getText() + "\n";
      message += (radio1.isSelected() ? "Na budgety" : "Budgeta Nety") + "\n";
      message += "Checkbox is" + ((check.isSelected()) ? "checked" : "unchecked");
      
      JOptionPane.showMessageDialog(null, message, "Itog", JOptionPane.PLAIN_MESSAGE);
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-09-19
@Rudy9966

String.split

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question