
正文
java黄色背景代码 java背景颜色代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用JAVA语言编写程序,使界面中包含3个标签,其背景分别为红、黄、蓝3色。
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
title/title
/head
body
div style="background:#FF0000; color:#FFF"背景为红色/div
div style="background:#EEEE00; color:#FFF"背景为黄色/div
div style="background:#436EEE; color:#FFF"背景为蓝色/div
/body
/html
颜色你自己调一下
相关问答
Q1: 背景为黄色,三个按钮在一行,拖动时可以缩小变大的JAVA布局程序
java GUI设计中,各种布局的搭配使用,都能实现你提的要求。多了解了几种熟悉的布局。
FlowLayout 流布局。BorderLayout边框布局。GridLayout网格布局
import java.awt.*;
import javax.swing.*;
public class FrameDemo extends JFrame {
private static final long serialVersionUID = 1L;
JButton jb1,jb2,jb3;
JPanel jp1;
public FrameDemo() {
jb1 = new JButton("Button1");
jb2 = new JButton("Button2");
jb3 = new JButton("Button3");
jp1 = new JPanel(new GridLayout(1, 3,50,0));
jp1.setBackground(Color.YELLOW);
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
this.add(jp1);
this.setLocation(300, 300);
this.pack();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String args[]) {
new FrameDemo();
}
}
Q2: java设定背景颜色
本来是在drawcomponent这个里边使用setBackgroundjava黄色背景代码,你想啊drawcomponent是继承JComponentjava黄色背景代码的所以它是一个容器java黄色背景代码,所以它同样有setBackground这个方法来设置它的背景颜色
但是因为你在设置它本身为一个画布,因为你用了paintComponent(Graphics g)
这个方法,所以setBackground这个方法即使你用了也看不到很大的效果。但是有一种取代的方法就是在paintComponent(Graphics g)方法中首先就用Graphics 所含有的方法g.setColor(Color.black);来设置背景颜色再用g.fillRect(0, 0, this.getWidth(), this.getHeight());来填满整个容器,这就达到了设置背景目的。然后你再g.setColor(其他颜色);来绘制其它图形.
具体代码:(在你以上的代码上修改了点)
public void paintComponent(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
g.setColor(Color.black);//这里设置背景颜色
g.fillRect(0, 0, this.getWidth(), this.getHeight());//这里填充背景颜色
double x=100;
double y=100;
double w=200;
double h=150;
Rectangle2D rect=new Rectangle2D.Double(x,y,w,h);
g2.setPaint(Color.white);//这里是你设置其他笔触颜色
g2.draw(rect);
Ellipse2D ellipse=new Ellipse2D.Double();
ellipse.setFrame(rect);
g2.draw(ellipse);
Point2D p1=new Point2D.Double(x-40,y-30);
Point2D p2=new Point2D.Double(x+w+40,y+h+30);
g2.draw(new Line2D.Double(p1,p2));
double centerx=rect.getCenterX();
double centery=rect.getCenterY();
double radius=150;
Ellipse2D circle=new Ellipse2D.Double();
circle.setFrameFromCenter(centerx,centery,centerx+125,centery+125);
g2.draw(circle);
}
测试结果图
Q3: 这段JAVA代码为什么背景都是黄色的?
java黄色背景代码你设值java黄色背景代码的panel的背景是黄色。。所以就是黄色了。。
给java黄色背景代码你改了下。。
Frame f = new Frame("TestFrame");
Panel p = new Panel();
p.setBackground(Color.RED);
Button b = new Button("click");
b.setBackground(Color.yellow);
p.add(b);
f.add(p);
f.setSize(500, 500);
f.setLocation(300, 300);
f.setVisible(true);
Q4: 编程JAVA程序:包含三个标签,其背景分别为红,黄,蓝三色的程序
你说java黄色背景代码的背景是整个背景还是标签背景java黄色背景代码??java黄色背景代码我两个都设置java黄色背景代码了你自己看吧 不要java黄色背景代码的删掉就行
import javax.swing.*;
import java.awt.*;
public class Main
{
public static void main(String args[])
{
//创建窗口
JFrame f = new JFrame("TestLabel");
//设置布局
f.setLayout(new GridLayout(1,3));
JPanel p1= new JPanel();
JPanel p2= new JPanel();
JPanel p3= new JPanel();
//新建标签
Label l1= new Label("label1");
Label l2= new Label("label2");
Label l3= new Label("label3");
//窗口大小
f.setSize(600,300);
//窗口颜色(整体背景色)
p1.setBackground(Color.red);
p2.setBackground(Color.yellow);
p3.setBackground(Color.blue);
//设置(标签的背景色)
l1.setBackground(Color.yellow);
l2.setBackground(Color.blue);
l3.setBackground(Color.red);
//调用面板
f.add(p1);
f.add(p2);
f.add(p3);
//添加标签
p1.add(l1);
p2.add(l2);
p3.add(l3);
//设置框架可见
f.setVisible(true);
//设置框架可以关闭
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
java黄色背景代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java背景颜色代码、java黄色背景代码的信息别忘了在本站进行查找喔。







