package com.company.Iguana;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.InputEvent;
public class MyCPS implements ChangeListener {
JSlider Slider;
JPanel panel;
JLabel label;
JFrame frame;
JComboBox Combo;
MyCPS() {
frame = new JFrame("CPS");
panel = new JPanel();
label = new JLabel();
Slider = new JSlider();
String[] Buttons = {"Left Click", "Right Click"};
JComboBox combo = new JComboBox(Buttons);
ImageIcon image = new ImageIcon("BOAROR.png");
frame.setIconImage(image.getImage());
frame.getContentPane().setBackground(Color.YELLOW);
frame.setTitle("Iguana.exe");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 420);
Slider = new JSlider(0, 23, 12);
Slider.setPreferredSize(new Dimension(400, 200));
Slider.setPaintTrack(true);
Slider.setMajorTickSpacing(4);
Slider.setPaintLabels(true);
Slider.setOrientation(SwingConstants.VERTICAL);
label.setText("CPS" + Slider.getValue());
label.setIcon(image);
Slider.addChangeListener(this);
panel.add(combo);
panel.add(Slider);
panel.add(label);
frame.add(panel);
frame.setSize(420,420);
frame.setVisible(true);
frame.pack();
}
@Override
public void stateChanged(ChangeEvent e) {
label.setText("CPS" + Slider.getValue());
if(e.equals(Slider.getValue())); <<<<<<<< Problem
System.out.println("Five");
}
}
每当我尝试放置if(e.equals(slider.getvalue());==5表示运算符“==”不能应用于“java.lang.object”、“int”
我只是想得到它每当我把cps作为5它会打印“5”回来作为一个测试我是相当新的,所以我可能做了一些愚蠢的错误
1条答案
按热度按时间ojsjcaue1#
错误是因为您试图比较对象,
e
类型,ChangeEvent
与Slider.getValue()
返回一个int
.你应该把它写成
检查
JSlider#getValue
了解更多。