问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
/*import java.awt.;
/*import java.awt.event.;
/*import javax.swing.;
/*import javax.swing.event.;
/**
这个程序是一个显示单个滑块和绘图的 Java 应用程序。
/
/public class WindowBlind extends JFrame implements ChangeListener
/{/**
- 这是出现在显示屏中的滑块。
- /
/** private JSlider slider;
/**
- 这是绘制的面板
- /
/**private JPanel panel;
/**
- 这保存了当前盲注高度,最初为 50。
- /
/** private int blindHeight = 50;
/**
- main 方法是 WindowBlind 程序的主要启动动作。
- /
/** public static void main (String[] args)
/** {
/** WindowBlind frame = new WindowBlind();
/** frame.setSize(400,400);
/** frame.setLocation(200,200);
/**frame.createGUI();
/frame.setVisible(true);
/} // end of main
/**
createGUI方法由main方法调用
设置图形用户界面。
/
/private void createGUI()
/{
/** // 设置主窗口特征
/** setDefaultCloseOperation(EXIT_ON_CLOSE);
/**Container window = getContentPane();
/**window.setLayout(new FlowLayout() );/** // 使用正确的初始设置创建可调节滑块
/**slider = new JSlider(JSlider.HORIZONTAL, 0, 100 , blindHeight);
/window.add(slider);
/ slider.addChangeListener(this);/** // 创建用于绘图的面板
/panel = new JPanel()
/ {
/** // 需要刷新屏幕时会自动调用油漆组件
/** public void paintComponent(Graphics g)
/** {/** // g is a cleared panel area /** super.paintComponent(g); // 绘制面板的背景 /** paintScreen(g); /** // 然后是需要的图形 /** }
/** };
/** panel.setPreferredSize(new Dimension(300, 300));
/** panel.setBackground(Color.cyan);
/** window.add(panel);
/** } // end of createGUI
/**
- stateChanged 方法被自动调用
- 调整滑块时
- 获取设置,更新blindHeight并引用屏幕
- /
/** public void stateChanged(ChangeEvent e)
/{
/ blindHeight = slider.getValue();
/** repaint(); // 强制刷新屏幕
/** } // end of stateChanged
/** - 刷新屏幕时重绘图形面板:
- 带有部分遮盖开口的百叶窗的窗框
- /
/** private void paintScreen(Graphics g)
/** {
/** drawWindow(g, Color.red, 120, 80, blindHeight);
/** } // end of paintScreen//添加一个窗口
/** private void drawWindow(Graphics g, Color c,int x, int y, int level){
/** x = 120;
/** y = 80;
/** g.setColor(c);
/** g.drawRect(x, y, 60, 100);
/** g.fillRect(x, y, 60, level);
/** }
/**} // end of WindowBlind