一段JAVA程序代码

来源:百度知道 编辑:UC知道 时间:2024/06/01 14:20:01
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.colorchooser.*;
public class Hp extends JFrame
{
DefaultColorSelectionModel model=new DefaultColorSelectionModel();
JColorChooser colorchooser=new JColorChooser(model);
JLabel label1=new JLabel("请选择颜色来改变背景色");
Font font=new Font("Serif",Font.ITALIC|Font.BOLD,40);
GridBagConstraints gcons=new GridBagConstraints();
Color color;
public static void main(String[]args)
{
Hp frame1=new Hp();
frame1.setTitle("JColorChooser 调色板");
frame1.setSize(500,500);
frame1.setVisible(true);
}
public Hp()
{
label1.setFont(font);
getContentPane().setLayout(new GridBagLayout());
gcons.weighty=1;
gcons.gridwidth=GridBagConstraints.REMAINDER;
getContentPane().add(label1,gcons);
gcons.weighty=2;

多了个分号,修改好的程序:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.colorchooser.*;

public class Hp extends JFrame {

private static final long serialVersionUID = 1L;
DefaultColorSelectionModel model = new DefaultColorSelectionModel();
JColorChooser colorchooser = new JColorChooser(model);
JLabel label1 = new JLabel("请选择颜色来改变背景色");
Font font = new Font("Serif", Font.ITALIC | Font.BOLD, 40);
GridBagConstraints gcons = new GridBagConstraints();
Color color;

public static void main(String[] args) {
Hp frame1 = new Hp();
frame1.setTitle("JColorChooser 调色板");
frame1.setSize(500, 500);
frame1.setVisible(true);
}

public Hp() {
label1.setFont(font);
getContentPane().setLayout(new GridBagLayout());
gcons.weighty = 1;
gcons.gridwidth = GridBagConstraints.REMAINDER;