关闭

JOptionPane_两个辅助类

187人阅读 评论(0) 收藏 举报

package swing;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Rectangle2D;
import java.util.Date;

import javax.swing.*;

/**
 * JOptionPane 的各种组合
 */
public class OptionDialogTest {
 public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   @Override
   public void run() {
    OptionDialogFrame frame = new OptionDialogFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
   }
  });
 }
}


class SampleComponent extends JComponent {
 public void paintComponent(Graphics g) {
  Graphics2D g2 = (Graphics2D) g;
  Rectangle2D rect = new Rectangle2D.Double(0, 0, this.getWidth()-1, this.getHeight()-1);
  g2.setPaint(Color.YELLOW);
  g2.fill(rect);
  g2.setPaint(Color.BLUE);
  g2.draw(rect);
 }
 
 public Dimension getPreferredSize() {
  return new Dimension(10, 10);
 }
}

class ButtonPanel extends JPanel {
 public ButtonPanel(String title, String... options) {
  this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title));
  this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  group = new ButtonGroup();
  
  for(String option : options) {
   JRadioButton b = new JRadioButton(option);
   b.setActionCommand(option);
   this.add(b);
   group.add(b);
   b.setSelected(option == options[0]);
  }
 }
 
 public String getSelection() {
  return group.getSelection().getActionCommand();
 }
 
 private ButtonGroup group;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:101273次
    • 积分:1753
    • 等级:
    • 排名:千里之外
    • 原创:85篇
    • 转载:0篇
    • 译文:0篇
    • 评论:37条
    文章分类
    最新评论