我是java的新手,我已经在谷歌搜索了一段时间的答案,但我找不到获得RGB背景颜色的方法,我只能找到如何设置java已经提供的主要颜色的背景颜色(例如,“Color.BLACK”)。 我正在使用JFrame。 请帮忙。 谢谢。 这是我的背景代码。
public void paintComponent(Graphics g){ super.paintComponent(g); this.setBackground(Color.PINK); //My current background colour code but I am looking to use a customisable RGB one. g.setColor(Color.BLACK); g.fillRect(0, 0, 40, y); tm.start(); }I am new to java and I have searched for an answer on Google for a while now, but I cannot find a way to get an RGB background colour, I can only find how to set a background colour from the main colours already provided by java(for example, "Color.BLACK"). I am using a JFrame. Please help. Thanks. In this is my background code.
public void paintComponent(Graphics g){ super.paintComponent(g); this.setBackground(Color.PINK); //My current background colour code but I am looking to use a customisable RGB one. g.setColor(Color.BLACK); g.fillRect(0, 0, 40, y); tm.start(); }最满意答案
缺少上下文,如果你的意思是Swing组件中的背景颜色(例如JFrame,JPanel),它们有方法getBackground()或setBackground(Color)。
JPanel panel = new JPanel(); Color yourColor = panel.getBackground();java中的颜色有很多返回颜色类型的方法,例如。
int rgbValue = yourColor.getRGB(); // Returns the RGB value representing the color in the default sRGB ColorModel. // or specific red, green, blue color value int red = yourColor.getRed(); int green = yourColor.getGreen(); int blue = yourColor.getBlue();The context is missing, if you mean background color in Swing component (e.g JFrame, JPanel) they have methods getBackground() or setBackground(Color).
JPanel panel = new JPanel(); Color yourColor = panel.getBackground();Color in java have lot of methods for return Color type eg.
int rgbValue = yourColor.getRGB(); // Returns the RGB value representing the color in the default sRGB ColorModel. // or specific red, green, blue color value int red = yourColor.getRed(); int green = yourColor.getGreen(); int blue = yourColor.getBlue();更多推荐
发布评论