永发信息网

如何在java消息框中添加背景图片?

答案:5  悬赏:80  手机版
解决时间 2021-02-15 00:44
如何在下面的程序弹出的框中添加图片:
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;
public class Test14 {


public static void main(String[] args) {
Neusoft_IP ip = new Neusoft_IP();
int i = ip.getIp();
Object[] options = {"宽带1","宽带2"};
Object n = JOptionPane.showInputDialog(null, "选择:", "宽带选择", JOptionPane.DEFAULT_OPTION, null, options, options[0]);
try {
Process p = Runtime.getRuntime().exec("Netsh");
BufferedOutputStream w = new BufferedOutputStream(p.getOutputStream());
final BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
Thread t = new Thread() {
public void run() {
try {
String line;
while ((line = r.readLine()) != null) {
System.out.println(line);
}
r.close();
} catch (Exception e) {
}
}
};
t.start();
w.write("interface ip\r\n".getBytes());
if ("宽带1".equals(n)) {
w.write("set address \"本地连接\" dhcp\r\n".getBytes());
w.write("set dns \"本地连接\" dhcp\r\n".getBytes());
String str2="宽带切换成功!";
JOptionPane.showMessageDialog(null,str2);
}
else if ("宽带2".equals(n)) {
w.write("set address \"本地连接\" dhcp\r\n".getBytes());
w.write("set dns \"本地连接\" dhcp\r\n".getBytes());
String str1="宽带切换成功!";
JOptionPane.showMessageDialog(null,str1);
}
w.flush();
w.write("quit\r\n".getBytes());
w.flush();
w.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
谢谢!
最佳答案
使用java.swing.ImageIcon类,然后在弹出消息对话框的时候用
ImageIcon image = ....;
JOptionPane.showMessageDialog(null,image);
就可以了

如果你的图片在你的硬盘上,例如:C:\1.jpg
ImageIcon 的构造方法可以用:
ImageIcon image = new ImageIcon("c:\\1.jpg");
全部回答
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import javax.swing.JOptionPane; public class Test14 { public static void main(String[] args) { Neusoft_IP ip = new Neusoft_IP(); int i = ip.getIp(); Object[] options = {"宽带1","宽带2"}; Object n = JOptionPane.showInputDialog(null, "选择:", "宽带选择", JOptionPane.DEFAULT_OPTION, null, options, options[0]); try { Process p = Runtime.getRuntime().exec("Netsh"); BufferedOutputStream w = new BufferedOutputStream(p.getOutputStream()); final BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); Thread t = new Thread() { public void run() { try { String line; while ((line = r.readLine()) != null) { System.out.println(line); } r.close(); } catch (Exception e) { } } }; t.start(); w.write("interface ip\r\n".getBytes()); if ("宽带1".equals(n)) { w.write("set address \"本地连接\" dhcp\r\n".getBytes()); w.write("set dns \"本地连接\" dhcp\r\n".getBytes()); String str2="宽带切换成功!"; JOptionPane.showMessageDialog(null,str2); } else if ("宽带2".equals(n)) { w.write("set address \"本地连接\" dhcp\r\n".getBytes()); w.write("set dns \"本地连接\" dhcp\r\n".getBytes()); String str1="宽带切换成功!"; JOptionPane.showMessageDialog(null,str1); } w.flush(); w.write("quit\r\n".getBytes()); w.flush(); w.close(); } catch (IOException e) { e.printStackTrace(); } } }
public void paintComponent(Graphics g) { ImageIcon icon = new ImageIcon("D://workspace//Amyself//src//2009517719856277802.jpg"); g.drawImage(icon.getImage(), 0, 0, frame.getSize().width,frame.getSize().height,frame); }
import javax.swing.*; joptionpane.showmessagedialog(this,"消息内容");
可以新建个面板,在面板里放入带图片的JLabel,填满面板即可。 JPanel jp = new JPanel(); //新建面板 jp.setLayout(new FlowLayout()); //设置面板布局 ImageIcon ii=new ImageIcon(getClass().getResource("/Picture/i.jpg")); JLabel uppicture=new JLabel(ii); //往面板里加入JLabel this.setVisible(true);下面是一个完整代码的例子; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ks extends JFrame implements ActionListener {     private static final Color red = null;     private JPanel jp = new JPanel();     JPanel topjp = new JPanel();     JPanel leftjp = new JPanel();     JPanel rightjp = new JPanel();     JButton cmanage = new JButton("客户资料管理");     JButton pmanage = new JButton("售票管理");     JButton wmanage = new JButton("票务管理");     JButton smanage = new JButton("购送票管理");     JButton dmanage = new JButton("定单信息管理");     JLabel index = new JLabel("航空订票系统");     Font jbfont = new Font("宋体", Font.BOLD, 20);     Font indexfont = new Font("华文隶书", Font.BOLD + Font.ITALIC, 50);     JLabel gnumber = new JLabel("管理员帐号");     JTextField textgnumber = new JTextField();     JLabel mname = new JLabel("密码");     JTextField textmname = new JTextField();     JButton select = new JButton("查询");     private JButton[] jb = { cmanage, dmanage, pmanage, smanage, wmanage };     JTable table = new JTable();     public Image image;     public ks() {         jp.setLayout(null);         leftjp.setLayout(null);         rightjp.setLayout(null);         jp.add(topjp);         jp.add(leftjp);         jp.add(rightjp);         leftjp.setBounds(0, 50, 230, 700);         topjp.add(index);         topjp.setBounds(0, 0, 1000, 70);         topjp.setBackground(Color.darkGray);         leftjp.setBackground(Color.lightGray);         rightjp.setBounds(200, 50, 800, 700);         rightjp.add(gnumber);         rightjp.add(textgnumber);         rightjp.add(mname);         rightjp.add(textmname);         rightjp.add(select);         for (int i = 0; i < 5; i++) {             jb[i].setBounds(20, 50 + i * 80, 180, 60);             leftjp.add(jb[i]);             jb[i].setFont(jbfont);             jb[i].addActionListener(this);         }         index.setFont(indexfont);         index.setForeground(Color.white);         gnumber.setBounds(70, 30, 100, 30);         textgnumber.setBounds(150, 30, 100, 30);         mname.setBounds(280, 30, 100, 30);         textmname.setBounds(330, 30, 100, 30);         select.setBounds(490, 30, 100, 30);         JLabel jl = new JLabel(new ImageIcon("C:\\Users\\LR\\Desktop\\1.png"));         jl.setBounds(0, 0, 1000, 700);         this.getLayeredPane().add(jl);// 设置背景为图片         this.add(jp);         this.setTitle("航空订票系统");         this.setBounds(0, 0, 1000, 700);         this.setVisible(true);         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     }     public void actionPerformed(ActionEvent e) {         if (e.getSource() == jb[0]) {         }     }     public static void main(String[] args) {         new ks();     } }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
魅族pro系统怎么升级(原来有提示,但是我不
永州市江华市水口镇水库情况
求 我才不会被女孩子欺负呢的类似长篇小说
QQ三国三机怪物等级计算
莲塘一中2011年择校费包括借读费具体是多少?
centos tmp目录怎么打开
我的百合买回家好几天了,怎么没有开花的迹象
一百多斤的跑步机怎么寄回四川?没有包装盒被
米哥哥8味香辣炸鸡饭在什么地方啊,我要过去
某药店经营的抗病毒药品在市场短缺的情况下提
去nature publish group当编辑怎么样
蒋峪镇人民调解中心这个地址在什么地方,我要
2015年统盟电子厂最近有招聘信息吗
桃源鹅庄怎么去啊,有知道地址的么
青城山前山怎么回成都
推荐资讯
一大块琥珀原石多少钱
7898烫染沙龙地址在什么地方,我要处理点事
电影《南京!南京》中最后死了的带脚链的女人
摩托车报废问题
好乐星KTV(广饶店)地址在哪,我要去那里办事
我们租赁别人的房产合同有失公允,对方只有权
停车场(振兴路)(振兴路南100米停车场)怎么去
刀剑英雄如何提高转身获取伤减石的机率
Visual c++ 6.0 安装完找不到怎么办
农村信用社atm(育英路12幢附近农贸市场停车场
OCR取词是什么
生华铁艺工程地址在哪,我要去那里办事
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?