精华内容
下载资源
问答
  • javasetbackground 不起作用?
    2021-03-06 20:00:33

    代码如下:importjavax.swing.JApplet;importjava.awt.*;publicclassSnowmanextendsJApplet{publicvoidpaint(Graphicspage){finalintMID=150;finalintTOP=50;setBackground(Color.cya...

    代码如下:

    import javax.swing.JApplet;

    import java.awt.*;

    public class Snowman extends JApplet

    {

    public void paint(Graphics page)

    {

    final int MID=150;

    final int TOP=50;

    setBackground(Color.cyan);

    page.setColor(Color.blue);

    page.fillRect(0,175,300,50);

    page.setColor(Color.yellow);

    page.fillOval(-40,-40,80,80);

    page.setColor(Color.green);

    page.fillOval(MID-20,TOP,40,40);

    page.fillOval(MID-35,TOP+35,70,50);

    page.fillOval(MID-50,TOP+80,100,60);

    page.setColor(Color.black);

    page.fillOval(MID-10,TOP+10,5,5);

    page.fillOval(MID+5,TOP+10,5,5);

    page.drawArc(MID-10,TOP+20,20,10,190,160);

    page.drawLine(MID-25,TOP+60,MID-50,TOP+40);

    page.drawLine(MID+25,TOP+60,MID+55,TOP+60);

    page.drawLine(MID-20,TOP+5,MID+20,TOP+5);

    page.fillRect(MID-15,TOP-20,30,25);

    }

    private void setOpaque(boolean b) {

    // TODO Auto-generated method stub

    }

    }

    展开

    更多相关内容
  • 在这个SSCCE代码中:这种方法工作label.setForeground(Color....label.setBackground(Color.BLUE);import java.awt.*;import javax.swing.*;public class LabelColorTest extends JPanel{static JLabel label;JPanel...

    在这个SSCCE代码中:

    这种方法工作

    label.setForeground(Color.GREEN);

    但下一个方法不行!

    label.setBackground(Color.BLUE);

    import java.awt.*;

    import javax.swing.*;

    public class LabelColorTest extends JPanel

    {

    static JLabel label;

    JPanel panel;

    public LabelColorTest()

    {

    label = new JLabel();

    label.setVerticalAlignment(JLabel.CENTER);

    label.setHorizontalAlignment(JLabel.CENTER);

    label.setText("Hello world");

    panel = new JPanel();

    panel.setLayout(new BorderLayout());

    panel.add(label, BorderLayout.CENTER);

    label.setForeground(Color.GREEN); //HERE

    label.setBackground(Color.BLUE); //HERE

    this.setLayout(new BorderLayout());

    this.add(panel);

    }

    private static void createAndShowGUI()

    {

    JFrame frame = new JFrame("Hellow world");

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setSize(400, 250);

    frame.add(new LabelColorTest(), BorderLayout.CENTER);

    frame.setVisible(true);

    }

    public static void main(String[] args)

    {

    SwingUtilities.invokeLater(new Runnable()

    {

    public void run()

    {

    UIManager.put("swing.boldMetal", Boolean.FALSE);

    createAndShowGUI();

    }

    });

    }

    }

    展开全文
  • 窗口背景颜色是指直接调用JFrame或者Frame的setBackground(Colorcolor)方法设置后显示出来的颜色。如果直接调用这个方法后,的确设置了背景颜色,但看到的却不是直接的JFrame或者Frame,而是JFrame.getContentPane()...

    窗口背景颜色是指直接调用JFrame或者Frame的setBackground(Color color)方法设置后显示出来的颜色。如果直接调用这个方法后,的确设置了背景颜色,但看到的却不是直接的JFrame或者Frame,而是JFrame.getContentPane(),而JFrame上的contentPane默认是Color.WHITE的,所以,无论你对JFrame或者Frame怎么设置背景颜色,你看到的都只是contentPane.

    解决方法:

    办法A:在完成初始化,调用getContentPane()方法得到一个contentPane容器,然后将其设置为不可见,即setVisible(false)。

    import javax.swing.*;

    import java.awt.*

    public class TestMenuBar1 {

    public static void main(String arg[]) {

    createNewMenu ck=new createNewMenu("第一个窗口");

    }

    }

    class createNewMenu extends JFrame{

    public createNewMenu(String title) {

    getContentPane().setVisible(false);

    setBackground(Color.blue); //设置窗口背景颜色

    setTitle(title);

    setBounds(200,200,500,500); //设置窗口位置和大小

    setVisible(true); //设置窗口可见

    }

    }

    办法B:直接加 this.getContentPane().setBackground(Color.blue);

    import java.awt.*;

    import javax.swing.*;

    public class TestMenuBar1 {

    public static void main(String arg[]) {

    createNewMenu ck=new createNewMenu("第一个窗口");

    }

    }

    class createNewMenu extends JFrame{

    public createNewMenu(String title) {

    setTitle(title);

    setBounds(200,200,500,500);

    setVisible(true);

    this.getContentPane().setBackground(Color.blue);

    }

    }

    展开全文
  • 1)在这里获取JavaNativeAccess库:[https://github.com/twall/jna/]2)这两个Java类将起到作用。请享用。package com.stackoverflow.util;import com.sun.jna.Library;import com.sun.jna.Native;import ...

    这是Win32控制台的解决方案。

    1)在这里获取JavaNativeAccess库:[https://github.com/twall/jna/]

    2)这两个Java类将起到作用。

    请享用。

    package com.stackoverflow.util;

    import com.sun.jna.Library;

    import com.sun.jna.Native;

    import com.sun.jna.Platform;

    import com.sun.jna.Structure;

    public class Win32 {

    public static final int STD_INPUT_HANDLE = -10;

    public static final int STD_OUTPUT_HANDLE = -11;

    public static final int STD_ERROR_HANDLE = -12;

    public static final short CONSOLE_FOREGROUND_COLOR_BLACK = 0x00;

    public static final short CONSOLE_FOREGROUND_COLOR_BLUE = 0x01;

    public static final short CONSOLE_FOREGROUND_COLOR_GREEN = 0x02;

    public static final short CONSOLE_FOREGROUND_COLOR_AQUA = 0x03;

    public static final short CONSOLE_FOREGROUND_COLOR_RED = 0x04;

    public static final short CONSOLE_FOREGROUND_COLOR_PURPLE = 0x05;

    public static final short CONSOLE_FOREGROUND_COLOR_YELLOW = 0x06;

    public static final short CONSOLE_FOREGROUND_COLOR_WHITE = 0x07;

    public static final short CONSOLE_FOREGROUND_COLOR_GRAY = 0x08;

    public static final short CONSOLE_FOREGROUND_COLOR_LIGHT_BLUE = 0x09;

    public static final short CONSOLE_FOREGROUND_COLOR_LIGHT_GREEN = 0x0A;

    public static final short CONSOLE_FOREGROUND_COLOR_LIGHT_AQUA = 0x0B;

    public static final short CONSOLE_FOREGROUND_COLOR_LIGHT_RED = 0x0C;

    public static final short CONSOLE_FOREGROUND_COLOR_LIGHT_PURPLE = 0x0D;

    public static final short CONSOLE_FOREGROUND_COLOR_LIGHT_YELLOW = 0x0E;

    public static final short CONSOLE_FOREGROUND_COLOR_BRIGHT_WHITE = 0x0F;

    public static final short CONSOLE_BACKGROUND_COLOR_BLACK = 0x00;

    public static final short CONSOLE_BACKGROUND_COLOR_BLUE = 0x10;

    public static final short CONSOLE_BACKGROUND_COLOR_GREEN = 0x20;

    public static final short CONSOLE_BACKGROUND_COLOR_AQUA = 0x30;

    public static final short CONSOLE_BACKGROUND_COLOR_RED = 0x40;

    public static final short CONSOLE_BACKGROUND_COLOR_PURPLE = 0x50;

    public static final short CONSOLE_BACKGROUND_COLOR_YELLOW = 0x60;

    public static final short CONSOLE_BACKGROUND_COLOR_WHITE = 0x70;

    public static final short CONSOLE_BACKGROUND_COLOR_GRAY = 0x80;

    public static final short CONSOLE_BACKGROUND_COLOR_LIGHT_BLUE = 0x90;

    public static final short CONSOLE_BACKGROUND_COLOR_LIGHT_GREEN = 0xA0;

    public static final short CONSOLE_BACKGROUND_COLOR_LIGHT_AQUA = 0xB0;

    public static final short CONSOLE_BACKGROUND_COLOR_LIGHT_RED = 0xC0;

    public static final short CONSOLE_BACKGROUND_COLOR_LIGHT_PURPLE = 0xD0;

    public static final short CONSOLE_BACKGROUND_COLOR_LIGHT_YELLOW = 0xE0;

    public static final short CONSOLE_BACKGROUND_COLOR_BRIGHT_WHITE = 0xF0;

    // typedef struct _COORD {

    // SHORT X;

    // SHORT Y;

    // } COORD, *PCOORD;

    public static class COORD extends Structure {

    public short X;

    public short Y;

    }

    // typedef struct _SMALL_RECT {

    // SHORT Left;

    // SHORT Top;

    // SHORT Right;

    // SHORT Bottom;

    // } SMALL_RECT;

    public static class SMALL_RECT extends Structure {

    public short Left;

    public short Top;

    public short Right;

    public short Bottom;

    }

    // typedef struct _CONSOLE_SCREEN_BUFFER_INFO {

    // COORD dwSize;

    // COORD dwCursorPosition;

    // WORD wAttributes;

    // SMALL_RECT srWindow;

    // COORD dwMaximumWindowSize;

    // } CONSOLE_SCREEN_BUFFER_INFO;

    public static class CONSOLE_SCREEN_BUFFER_INFO extends Structure {

    public COORD dwSize;

    public COORD dwCursorPosition;

    public short wAttributes;

    public SMALL_RECT srWindow;

    public COORD dwMaximumWindowSize;

    }

    // Source: https://github.com/twall/jna/nonav/javadoc/index.html

    public interface Kernel32 extends Library {

    Kernel32 DLL = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);

    // HANDLE WINAPI GetStdHandle(

    // __in DWORD nStdHandle

    // );

    public int GetStdHandle(

    int nStdHandle);

    // BOOL WINAPI SetConsoleTextAttribute(

    // __in HANDLE hConsoleOutput,

    // __in WORD wAttributes

    // );

    public boolean SetConsoleTextAttribute(

    int in_hConsoleOutput,

    short in_wAttributes);

    // BOOL WINAPI GetConsoleScreenBufferInfo(

    // __in HANDLE hConsoleOutput,

    // __out PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo

    // );

    public boolean GetConsoleScreenBufferInfo(

    int in_hConsoleOutput,

    CONSOLE_SCREEN_BUFFER_INFO out_lpConsoleScreenBufferInfo);

    // DWORD WINAPI GetLastError(void);

    public int GetLastError();

    }

    }

    package com.stackoverflow.util;

    import java.io.PrintStream;

    import com.stackoverflow.util.Win32.Kernel32;

    public class ConsoleUtil {

    public static void main(String[] args)

    throws Exception {

    System.out.print("abc");

    static_color_print(

    System.out,

    "def",

    Win32.CONSOLE_BACKGROUND_COLOR_RED,

    Win32.CONSOLE_FOREGROUND_COLOR_BRIGHT_WHITE);

    System.out.print("def");

    System.out.println();

    }

    private static Win32.CONSOLE_SCREEN_BUFFER_INFO _static_console_screen_buffer_info = null;

    public static void static_save_settings() {

    if (null == _static_console_screen_buffer_info) {

    _static_console_screen_buffer_info = new Win32.CONSOLE_SCREEN_BUFFER_INFO();

    }

    int stdout_handle = Kernel32.DLL.GetStdHandle(Win32.STD_OUTPUT_HANDLE);

    Kernel32.DLL.GetConsoleScreenBufferInfo(stdout_handle, _static_console_screen_buffer_info);

    }

    public static void static_restore_color()

    throws Exception {

    if (null == _static_console_screen_buffer_info) {

    throw new Exception("Internal error: Must save settings before restore");

    }

    int stdout_handle = Kernel32.DLL.GetStdHandle(Win32.STD_OUTPUT_HANDLE);

    Kernel32.DLL.SetConsoleTextAttribute(

    stdout_handle,

    _static_console_screen_buffer_info.wAttributes);

    }

    public static void static_set_color(Short background_color, Short foreground_color) {

    int stdout_handle = Kernel32.DLL.GetStdHandle(Win32.STD_OUTPUT_HANDLE);

    if (null == background_color || null == foreground_color) {

    Win32.CONSOLE_SCREEN_BUFFER_INFO console_screen_buffer_info =

    new Win32.CONSOLE_SCREEN_BUFFER_INFO();

    Kernel32.DLL.GetConsoleScreenBufferInfo(stdout_handle, console_screen_buffer_info);

    short current_bg_and_fg_color = console_screen_buffer_info.wAttributes;

    if (null == background_color) {

    short current_bg_color = (short) (current_bg_and_fg_color / 0x10);

    background_color = new Short(current_bg_color);

    }

    if (null == foreground_color) {

    short current_fg_color = (short) (current_bg_and_fg_color % 0x10);

    foreground_color = new Short(current_fg_color);

    }

    }

    short bg_and_fg_color =

    (short) (background_color.shortValue() | foreground_color.shortValue());

    Kernel32.DLL.SetConsoleTextAttribute(stdout_handle, bg_and_fg_color);

    }

    public static void static_color_print(

    PrintStream ostream,

    T value,

    Short background_color,

    Short foreground_color)

    throws Exception {

    static_save_settings();

    try {

    static_set_color(background_color, foreground_color);

    ostream.print(value);

    }

    finally {

    static_restore_color();

    }

    }

    public static void static_color_println(

    PrintStream ostream,

    T value,

    Short background_color,

    Short foreground_color)

    throws Exception {

    static_save_settings();

    try {

    static_set_color(background_color, foreground_color);

    ostream.println(value);

    }

    finally {

    static_restore_color();

    }

    }

    }

    展开全文
  • [Java] Font/Color/Event 字体/颜色/事件综合import java.awt.*;import java.awt.event.*;public class FontTest {Frame f = new Frame("FontTest");Panel p1 = new Panel();Panel p2 = new Panel();Panel p3 = new ...
  • 利用JFrame创建的窗口分别包含一个标题、最小化按钮、最大化按钮和关闭按钮1、在你使用JFrame创建窗体时的情况:在你直接调用setBackground(Color.red)这个方法后,你的确设置了JFrame的背景颜色,而你看到的却不是...
  • Java计算器源程序.rar

    2019-07-10 09:42:18
     setBackground(Color.lightGray); //设置Applet背景色  setForeground(Color.blue); //设置Applet前景色   for(int i=9;i>=0;i--){   b[i]=new Button(Integer.toString(i)); //实例化数字按钮   panel2...
  • 按注释完成程序import java.awt.*;import java.awt.event.*;import javax.swing.*;public class ButtonTestApplet extends JApplet{public void init(){ButtonPanel buttonpanel = new ButtonPanel();Container ...
  • java窗口背景颜色设置

    千次阅读 2021-03-21 09:35:41
    窗口背景颜色是指直接调用JFrame或者Frame的setBackground(Color color)方法设置后显示出来的颜色。如果直接调用这个方法后,的确设置了背景颜色,但看到的却不是直接的JFrame或者Frame,而是JFrame.getContentPane...
  • import java.awt.Color;import javax.swing.*;public class MyDraw{public static void main(String[] args){//创建框架JFrame myFrame=new JFrame("图画");//myFrame.setLocation(200, 300);//第1参数表示离左屏幕...
  • 背景颜色的设置

    千次阅读 2021-03-06 22:29:56
    背景颜色的设置请教各位,为什么我用setBackground()方法改变不了JLabel的背景颜色?搜索更多相关的解决方案:颜色----------------解决方案--------------------------------------------------------不会吧?...
  • TextView.setBackgroundResource(R.color.xxxxxx)TextView.setBackgroundResource(R.drawable.xxxxxx)用setBackgroundResource方法即可搞定很方便TextView.setTextColor(getResources().getColor(R.color.white))...
  • 在控制进行初步格式展示,包含字体(加粗,加斜,高亮等)以及设置字体颜色以及背景色。
  • java计算器程序.doc

    2012-10-10 17:06:11
    //Lb5.setBackground(Color.white); Lb6.setBackground(Color.white); Lb7.setBackground(Color.white); Lb8.setBackground(Color.white); Lb9.setBackground(Color.white); Lb10.setBackground(Color.gray); ...
  • JAVA Color

    千次阅读 2019-09-27 15:57:41
    Color类用于定义颜色java.awt.Color中提供了13个预定义的常量用来表示13中标准颜色,分别是:  public static final Color white白色。 public static final Color light_Gray浅灰色。 public static final ...
  • java GUI 改变背景颜色

    2021-02-12 20:42:48
    运行编译后安“文件”“changecolour”中选“red”“blue”应该能实现窗口中背景色的改变可是我这个即没报错也没变色求高手帮忙改改啊谢谢啦!!importjava.awt.*;importjava.awt.e...运行编译后 安“文件”...
  • Java Swing - 如何设置选定的文本颜色

    千次阅读 2021-02-26 17:42:21
    import java.awt.Color;import javax.swing.JFrame;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.WindowConstants;import javax.swing.text.DefaultCaret;public class Main {p...
  • java点击按钮换背景颜色

    千次阅读 2021-02-28 17:08:45
    创建一个AWT面板,该面板包含3个不同颜色名称的按钮,单击每个按钮时应使窗口的背景色显示为相应的颜色。importjava.awt.*;importjava.awt.event.*;publicclassChangecolorextendsMou...创建一个AWT面板,该面板包含...
  • java 背景颜色更改

    2021-02-12 13:00:13
    @Author: your name* @Date: 2020-10-28 22:38:26* @LastEditTime: 2020-10-29 10:01:15* @LastEditors: Please set LastEditors* @Description: In User Settings Edit* @FilePath: /java/Ima...
  • 今天我用GUI图形绘制组件,做了...这个图形绘制程序一共5个java文件构成: colorButton.java实现了选择颜色按钮的相关功能 lineButton.java实现了选择图形按钮的相关功能 drawingDesk.java实现了画图区域的画图功能 d
  • 窗口背景颜色是指直接调用JFrame或者Frame的setBackground(Colorcolor)方法设置后显示出来的颜色。如果直接调用这个方法后,的确设置了背景颜色,但看到的却不是直接的JFrame或者Frame,而是JFrame.getContentPane()...
  • java 点击按纽改变背景颜色

    千次阅读 2021-02-12 23:31:40
    展开全部分析题目:一 分析布局: 题目明确的指出了按钮e69da5e887aa62616964757a686964616f31333366306532的位置和大小 ,那么说明需要使用的布局是空布局(绝对...//设置为绝对布局二了解颜色. Color 可以通过红,绿,蓝...
  • 怎样改变java中按钮的字体和颜色

    千次阅读 2021-02-12 13:41:59
    对于上面这个问题,不少java初学者都会碰到。很多人通过Java的API文档查询的时候首先想到的是通过Graphics类来解决这个问题,但是在构建的过程中却遇到了困难。为什么呢,因为Graphics是java的一个抽象类。而抽象类...
  • 点击不同按钮切换面板背景颜色 import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ...public class ... this.setSize(500,500); t
  • 3.2 Color类 3.3 Font类和FontMetrics类 3.3.2 FontMetrics类 3.4 常用的绘图方法 3.4.1 绘制直线 3.4.2 绘制矩形 3.4.3 绘制椭圆 3.4.4 绘制弧形 3.4.5 绘制多边形和折线段 3.4.6 清除绘制的图形 3.5 ...
  • button.setBackground(Color.RED);//设置background颜色 button.setOpaque(true); //foreground设置透明 button.setBorderPainted(false); //最后显示红色 或者设置foreground颜色,这样会把background盖住,然后...
  • java程序画雪人

    2013-11-01 13:23:44
    setBackground(Color.cyan); // 设置背景色 page.setColor(Color.blue); // 设置前景色 page.fillRect(0,175,300,50); //ground page.setColor(Color.yellow); page.fillOval(-40,-40,80,80); //sun...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 17,025
精华内容 6,810
关键字:

java里setbackground(color.blue)颜色有哪些

java 订阅