JAVA创建文本区 要求如下
要求在背景色界面插入个文本区但不要全部把背景色覆盖掉代码如下求大神指导importjava.awt.*;importjavax.swing.*;importjava.aw...
要求在背景色界面插入个文本区但不要全部把背景色覆盖掉 代码如下求大神指导
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JR extends JFrame
{
private JPanel p1,p2;
private JButton button1;
private JLabel label1;
private JRadioButton yellow,green,blue;
private ButtonGroup buttonGroup;
public JR(JFrame f)
{
Container c= getContentPane();
f.add(c);
p1=new JPanel(); //创建一个用来显示颜色的面板对象
p1.setBackground(Color.YELLOW);
c.add(p1,BorderLayout.CENTER);
BorderLayout b1=new BorderLayout(); //按钮组件
Container p1=getContentPane();
button1=new JButton("按钮1");
button1.setFont(new Font("Serif",Font.PLAIN,14));
p1.add("West",button1);
label1 =new JLabel("标签"); //标签组件
label1.setFont(new Font("Serif",Font.PLAIN,14));
p1.add("North",label1);
buttonGroup=new ButtonGroup(); //创建单选按钮组
yellow= new JRadioButton("黄色",true); //单选按钮选项
green= new JRadioButton("绿色");
blue= new JRadioButton("蓝色");
yellow.setFont(new Font("Serif", Font.PLAIN, 14));
green.setFont(new Font("Serif", Font.PLAIN, 14));
blue.setFont(new Font("Serif", Font.PLAIN, 14));
buttonGroup.add(yellow);buttonGroup.add(green);buttonGroup.add(blue);
rHandler h=new rHandler();
yellow.addItemListener(h);
blue.addItemListener(h);
green.addItemListener(h);
p2=new JPanel();
p2.add(yellow);p2.add(green);p2.add(blue);
c.add(p2,BorderLayout.SOUTH);
f.setVisible(true);
}
public static void main(String[] args){
JR application = new JR(new JF0("题目8-3"));
}
private class rHandler implements ItemListener{
public void itemStateChanged(ItemEvent event){
if(yellow.isSelected()) p1.setBackground(Color.yellow);
else if (green.isSelected()) p1.setBackground(Color.GREEN);
else p1.setBackground(Color.BLUE);
}
}
} 展开
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JR extends JFrame
{
private JPanel p1,p2;
private JButton button1;
private JLabel label1;
private JRadioButton yellow,green,blue;
private ButtonGroup buttonGroup;
public JR(JFrame f)
{
Container c= getContentPane();
f.add(c);
p1=new JPanel(); //创建一个用来显示颜色的面板对象
p1.setBackground(Color.YELLOW);
c.add(p1,BorderLayout.CENTER);
BorderLayout b1=new BorderLayout(); //按钮组件
Container p1=getContentPane();
button1=new JButton("按钮1");
button1.setFont(new Font("Serif",Font.PLAIN,14));
p1.add("West",button1);
label1 =new JLabel("标签"); //标签组件
label1.setFont(new Font("Serif",Font.PLAIN,14));
p1.add("North",label1);
buttonGroup=new ButtonGroup(); //创建单选按钮组
yellow= new JRadioButton("黄色",true); //单选按钮选项
green= new JRadioButton("绿色");
blue= new JRadioButton("蓝色");
yellow.setFont(new Font("Serif", Font.PLAIN, 14));
green.setFont(new Font("Serif", Font.PLAIN, 14));
blue.setFont(new Font("Serif", Font.PLAIN, 14));
buttonGroup.add(yellow);buttonGroup.add(green);buttonGroup.add(blue);
rHandler h=new rHandler();
yellow.addItemListener(h);
blue.addItemListener(h);
green.addItemListener(h);
p2=new JPanel();
p2.add(yellow);p2.add(green);p2.add(blue);
c.add(p2,BorderLayout.SOUTH);
f.setVisible(true);
}
public static void main(String[] args){
JR application = new JR(new JF0("题目8-3"));
}
private class rHandler implements ItemListener{
public void itemStateChanged(ItemEvent event){
if(yellow.isSelected()) p1.setBackground(Color.yellow);
else if (green.isSelected()) p1.setBackground(Color.GREEN);
else p1.setBackground(Color.BLUE);
}
}
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询