开发者

JComboBox gets stuck after changing a JTextField

I've made a GUI with JFrame which includes a JComboBox with several JTextFields. When I choose an item in the JComboBox the text fields changes their values and I am suppose to be able to change them. The thing is, when I've chosen an item and changes a value the combo box gets stuck with that certain item and I cant choose another from the combo box. (The drop down menu wont show how much I press it). Here's the GUI class and the ActionListener classes just calls a method in my GUI class.

Can the problem be with I am using static methods and variables?

package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.Toolkit;
import java.util.HashMap;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import GUIListeners.CloseListener;
import GUIListeners.RoleBoxListener;
import GUIListeners.SaveEditListener;
import Simulation.Project;

public class EditProjectGUI extends JFrame {
    private static Project project;
    private JLabel editLabel, selectRole, savedLabel;
    private static JComboBox roleBox;
    private JLabel preConceptLabel, conceptLabel, projectLabel, preRampLabel, rampLabel, highVolumeLabel, preEOLLabel, EOLLabel;
    private static JTextField preConceptText, conceptText, projectText, preRampText, rampText, highVolumeText, preEOLText, EOLText;
    private JButton saveButton, cancelButton;

    public EditProjectGUI(Project project)     {

        this.editLabel = new JLabel("Edit Projects Details");
        editLabel.setFont(new Font("sansserif", Font.BOLD, 20));
        editLabel.setForeground(new Color(83, 142, 213));
        selectRole = new JLabel("Select role: ");
        this.project = project;

        saveButton = new JButton("Save");
        saveButton.addActionListener(new SaveEditListener());
        cancelButton = new JButton("Cancel");
        cancelButton.addActionListener(new CloseListener(this));

        savedLabel = new JLabel("Not saved");
        savedLabel.setForeground(new Color(192, 80, 77));

        setTitle("Edit Projects Data");
        int xSize = 400;
        int ySize = 300;
        setSize(xSize, ySize);
        setVisible(true);
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension currentScreen = kit.getScreenSize();

        this.setBounds(currentScreen.width / 2 - xSize / 2, currentScreen.height / 2 - ySize / 2, xSize, ySize);

        setLa开发者_Python百科yout(new BorderLayout());

        add(editLabel, "North");

        String[] roles = { "OPM", "MM", "SE", "QM", "SCP" };
        roleBox = new JComboBox(roles);
        roleBox.addActionListener(new RoleBoxListener(this));

        Panel centerPanel = new Panel();
        centerPanel.setLayout(new GridLayout(9, 2));

        preConceptLabel = new JLabel("Pre-Concept: ");
        conceptLabel = new JLabel("Concept: ");
        projectLabel = new JLabel("Project: ");
        preRampLabel = new JLabel("Pre-Ramp: ");
        rampLabel = new JLabel("Ramp: ");
        highVolumeLabel = new JLabel("High Volume: ");
        preEOLLabel = new JLabel("Pre-EoL: ");
        EOLLabel = new JLabel("EoL: ");

        preConceptText = new JTextField();
        conceptText = new JTextField();
        projectText = new JTextField();
        preRampText = new JTextField();
        rampText = new JTextField();
        highVolumeText = new JTextField();
        preEOLText = new JTextField();
        EOLText = new JTextField();


        centerPanel.add(selectRole);
        centerPanel.add(roleBox);
        centerPanel.add(preConceptLabel);
        centerPanel.add(preConceptText);
        centerPanel.add(conceptLabel);
        centerPanel.add(conceptText);
        centerPanel.add(projectLabel);
        centerPanel.add(projectText);
        centerPanel.add(preRampLabel);
        centerPanel.add(preRampText);
        centerPanel.add(rampLabel);
        centerPanel.add(rampText);
        centerPanel.add(highVolumeLabel);
        centerPanel.add(highVolumeText);
        centerPanel.add(preEOLLabel);
        centerPanel.add(preEOLText);
        centerPanel.add(EOLLabel);
        centerPanel.add(EOLText);

        add(centerPanel, "Center");

        Panel southPanel = new Panel();
        southPanel.setLayout(new FlowLayout());
        southPanel.add(saveButton);
        southPanel.add(cancelButton);
        southPanel.add(savedLabel);
        add(southPanel, "South");

        updateTextField(this);
    }

    public static void updateTextField(JFrame frame) {
        String role = (String) roleBox.getSelectedItem();
        HashMap<String, Double> map = project.getMap(role);

        preConceptText.setText(map.get("Pre-Concept").toString());
        conceptText.setText(map.get("Concept").toString());
        projectText.setText(map.get("Project").toString());
        preRampText.setText(map.get("Pre-Ramp").toString());
        rampText.setText(map.get("Ramp").toString());
        highVolumeText.setText(map.get("High Volume").toString());
        preEOLText.setText(map.get("Pre-EoL").toString());
        EOLText.setText(map.get("EoL").toString());

        frame.validate();
    }

    public static void save() {
        String role = (String) roleBox.getSelectedItem();
        HashMap<String, Double> map = new HashMap<String, Double>();

        map.put("Pre-Concept", new Double(preConceptText.getText()));
        map.put("Concept", new Double(conceptText.getText()));
        map.put("Project", new Double(projectText.getText()));
        map.put("Pre-Ramp", new Double(preRampText.getText()));
        map.put("Ramp", new Double(rampText.getText()));
        map.put("High Volume", new Double(highVolumeText.getText()));
        map.put("Pre-EoL", new Double(preEOLText.getText()));
        map.put("EoL", new Double(EOLText.getText()));

        project.setMap(map, role);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜