java上机报告.doc
文本预览下载声明
Java与面向对象程序设计上机报告(第11周)
班 级 10 学 号 姓 名
第一题:
PP6.12 修改第5章的QuoteOptions程序,改变原来的用户界面视觉外观。将单选按钮纵向排列,同时围在一个边框内,并排在引用语标签的左侧。
提示:参考例题5.24 5.25
源程序:
import java.awt.*;
import javax.swing.*;
public class QuoteOptions
{
public static void main (String[] args)
{
JFrame frame = new JFrame (Quote Options);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
QuoteOptionsPanel panel = new QuoteOptionsPanel();
frame.getContentPane().add (panel);
frame.pack();
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class QuoteOptionsPanel extends JPanel
{
private JLabel quote;
private JRadioButton comedy, philosophy, carpentry;
private String comedyQuote, philosophyQuote, carpentryQuote;
//-----------------------------------------------------------------
// Sets up a panel with a label and a set of radio buttons
// that control its text.
//-----------------------------------------------------------------
public QuoteOptionsPanel()
{
setLayout(new GridLayout(1,2));
JFrame frame = new JFrame (Border Demo);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout (new GridLayout (1, 2, 5, 10));
panel.setBorder (BorderFactory.createEmptyBorder (8, 8, 8, 8));
comedyQuote = Take my wife, please.;
philosophyQuote = I think, therefore I am.;
carpentryQuote = Measure twice. Cut once.;
quote = new JLabel (comedyQuote);
quote.setFont (new Font (Helvetica, Font.BOLD, 24));
comedy = new JRadioButton (Comedy, true);
comedy.setBackground (Color.orange);
philosophy = new JRadioButton (Philosophy);
philosophy.setBackground (Color.orange);
carpentry = new JRadioButton (Carpentry);
carpentry.setBackground (Color.orange);
ButtonGroup group = new ButtonGroup();
group.add (comedy);
显示全部