我是 Java 圖形的新手,我正在嘗試?yán)L制一個(gè)矩形。該矩形填充了由 3 個(gè)滑塊設(shè)置的顏色。問題是該正方形未打印在屏幕上。誰能幫我?import java.awt.Color;import java.awt.FlowLayout;import java.awt.Frame;import java.awt.Graphics;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JSlider;import javax.swing.JTextField;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;/* * Program description: Write a Java application which includes 3 sliders which enables * the user to set the color * of a 100x100 square. The square will be drawn using a * specific component (Canvas, etc.). * Author: Hornai Vlad * Date: 24.05.2019 */public class Square extends JPanel implements ChangeListener{ JPanel panel; JSlider r,g,b; JLabel rl,gl,bl; int red,green,blue; Square() { //set the layout setLayout(new FlowLayout()); //the panel panel = new JPanel(); //bounds of the panel panel.setBounds(20,40,300,300); rl = new JLabel("r"); rl.setBounds(10, 50, 15, 15); //the first slider r = new JSlider(0,255,0); r.setPaintTrack(true); r.setPaintTicks(true); r.setPaintLabels(true); } 我嘗試了幾個(gè)選項(xiàng),這個(gè)對(duì)我來說有邏輯,我不知道顯示正方形的原因是什么。一開始我認(rèn)為面板不夠大,所以我把它弄大了,但結(jié)果是一樣的。
1 回答

至尊寶的傳說
TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊
通過簡(jiǎn)單地復(fù)制和粘貼你的代碼,這就是我在我的系統(tǒng)上看到的。你確定你沒有修復(fù)你的代碼?
添加回答
舉報(bào)
0/150
提交
取消