关于java的图文混排
答案:1 悬赏:10 手机版
解决时间 2021-08-12 06:16
- 提问者网友:不爱我么
- 2021-08-11 16:35
怎样用java进行图文混排功能啊?都说用jeditorpane,可是都是加载网页的例子,谁能给个真正图文混排的例子啊?例如插入图片等功能,简要写写代码吧??
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-08-11 18:15
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() ; }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯