如何在java消息框中添加背景图片?
如何在下面的程序弹出的框中添加图片:importjava.io.BufferedOutputStream;importjava.io.BufferedReader;imp...
如何在下面的程序弹出的框中添加图片:
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;
public class Test14 {
/**
* @param args
*/
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();
}
}
}
谢谢! 展开
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;
public class Test14 {
/**
* @param args
*/
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();
}
}
}
谢谢! 展开
4个回答
推荐于2017-09-17 · 知道合伙人互联网行家
关注
展开全部
可以新建个面板,在面板里放入带图片的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();
}
}
展开全部
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;
public class Test14 {
/**
* @param args
*/
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();
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JOptionPane;
public class Test14 {
/**
* @param args
*/
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");
ImageIcon image = ....;
JOptionPane.showMessageDialog(null,image);
就可以了
如果你的图片在你的硬盘上,例如:C:\1.jpg
ImageIcon 的构造方法可以用:
ImageIcon image = new ImageIcon("c:\\1.jpg");
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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);
}
ImageIcon icon = new ImageIcon("D://workspace//Amyself//src//2009517719856277802.jpg");
g.drawImage(icon.getImage(), 0, 0, frame.getSize().width,frame.getSize().height,frame);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |