关于java的图文混排
怎样用java进行图文混排功能啊?都说用jeditorpane,可是都是加载网页的例子,谁能给个真正图文混排的例子啊?例如插入图片等功能,简要写写代码吧??...
怎样用java进行图文混排功能啊?都说用jeditorpane,可是都是加载网页的例子,谁能给个真正图文混排的例子啊?例如插入图片等功能,简要写写代码吧??
展开
1个回答
2013-11-17
展开全部
import java.io.File ;import java.awt.Container ;import java.awt.GridLayout ;import java.awt.event.WindowAdapter ;import java.awt.event.ItemListener ;import java.awt.event.ItemEvent ;import java.awt.event.WindowEvent ;import javax.swing.JFrame ;import javax.swing.JPanel ;import javax.swing.JRadioButton ;import javax.swing.ButtonGroup ;import javax.swing.BorderFactory ;import javax.swing.ImageIcon ;class MyRadio implements ItemListener{ private String right = "d:" + File.separator + "right.png" ; private String wrong = "d:" + File.separator + "wrong.gif" ; private JFrame frame = new JFrame("Welcome TO MLDN") ; private Container cont = frame.getContentPane() ; private JRadioButton jrb1 = new JRadioButton("男",new ImageIcon(right),true) ; private JRadioButton jrb2 = new JRadioButton("女",new ImageIcon(wrong),false) ; private JPanel pan = new JPanel() ; public MyRadio(){ pan.setBorder(BorderFactory.createTitledBorder("选择性别")) ; // 设置一个边框的显示条 pan.setLayout(new GridLayout(1,3)) ; pan.add(this.jrb1) ; pan.add(this.jrb2) ; ButtonGroup group = new ButtonGroup() ; group.add(this.jrb1) ; group.add(this.jrb2) ; jrb1.addItemListener(this) ; jrb2.addItemListener(this) ;
cont.add(pan) ; this.frame.setSize(300,80) ; this.frame.setVisible(true) ; this.frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent obj){ System.exit(1) ; } }) ; } public void itemStateChanged(ItemEvent e){ if(e.getSource()==jrb1){ jrb1.setIcon(new ImageIcon(right)) ; jrb2.setIcon(new ImageIcon(wrong)) ; }else{ jrb1.setIcon(new ImageIcon(wrong)) ; jrb2.setIcon(new ImageIcon(right)) ; } }};public class JRadioButtonDemo03{ public static void main(String args[]){ new MyRadio() ; }
cont.add(pan) ; this.frame.setSize(300,80) ; this.frame.setVisible(true) ; this.frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent obj){ System.exit(1) ; } }) ; } public void itemStateChanged(ItemEvent e){ if(e.getSource()==jrb1){ jrb1.setIcon(new ImageIcon(right)) ; jrb2.setIcon(new ImageIcon(wrong)) ; }else{ jrb1.setIcon(new ImageIcon(wrong)) ; jrb2.setIcon(new ImageIcon(right)) ; } }};public class JRadioButtonDemo03{ public static void main(String args[]){ new MyRadio() ; }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询