public class Dome extends javax.swing.JFrame { JLabel topLabel;
JLabel huiyixinxi,yudingxinxi,yanshi,tiqianjiesu;
JButton exitButton,loginButton; /** Creates new form Dome */
public Dome() {
initComponents();
} /** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
this.setBounds(0, 0, 1024, 768);
this.setResizable(false);//
topLabel=new JLabel();
topLabel.setIcon(new ImageIcon("images/mitbg.bmp") );
add(topLabel);
topLabel.setLayout(null); yudingxinxi = new JLabel("预定信息");
yudingxinxi.setForeground(Color.WHITE);
huiyixinxi = new JLabel("会议信息");
yanshi = new JLabel("会议延时");
tiqianjiesu = new JLabel("提前结束");
exitButton = new JButton("退 出");
loginButton = new JButton("登 录"); ButtonListener bListener = new ButtonListener();
// 按钮注册事件监听器
exitButton.addActionListener(bListener);
loginButton.addActionListener(bListener); MyKeyListener keylis=new MyKeyListener(); yudingxinxi.setSize(45,20);
yudingxinxi.setLocation(40,280);
yudingxinxi.setIcon(new ImageIcon("images/huiyi.bmp"));
topLabel.add(yudingxinxi); yanshi.setSize(50,20);
yanshi.setLocation(85,280);
topLabel.add(yanshi); huiyixinxi.setSize(40,20);
huiyixinxi.setLocation(140,280);
topLabel.add(huiyixinxi); tiqianjiesu.setSize(50,20);
tiqianjiesu.setLocation(195,280);
topLabel.add(tiqianjiesu); exitButton.setSize(80,20);
exitButton.setLocation(260,280);
topLabel.add(exitButton); loginButton.setSize(80,20);
loginButton.setLocation(350,280);
topLabel.add(loginButton); setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
//setSize(500,350);
setVisible(true); }// </editor-fold>
//GEN-END:initComponents /**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Dome().setVisible(true);
}
});
}
private void checkNamePwd(){
} private void exitWindow(){
System.exit(0);
} class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// 获取事件源
Object source = e.getSource();
if(source == exitButton)
{
exitWindow();
}
else if(source == loginButton)
{
checkNamePwd();
}
}
} class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent ke){
int code=ke.getKeyCode();
if(code==10){
checkNamePwd();
}
else if(code==27){
exitWindow();
}
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
// End of variables declaration//GEN-END:variables
}
}
我这段代码就是不会把图片显示出来 求指点swingJFrame
JLabel huiyixinxi,yudingxinxi,yanshi,tiqianjiesu;
JButton exitButton,loginButton; /** Creates new form Dome */
public Dome() {
initComponents();
} /** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
this.setBounds(0, 0, 1024, 768);
this.setResizable(false);//
topLabel=new JLabel();
topLabel.setIcon(new ImageIcon("images/mitbg.bmp") );
add(topLabel);
topLabel.setLayout(null); yudingxinxi = new JLabel("预定信息");
yudingxinxi.setForeground(Color.WHITE);
huiyixinxi = new JLabel("会议信息");
yanshi = new JLabel("会议延时");
tiqianjiesu = new JLabel("提前结束");
exitButton = new JButton("退 出");
loginButton = new JButton("登 录"); ButtonListener bListener = new ButtonListener();
// 按钮注册事件监听器
exitButton.addActionListener(bListener);
loginButton.addActionListener(bListener); MyKeyListener keylis=new MyKeyListener(); yudingxinxi.setSize(45,20);
yudingxinxi.setLocation(40,280);
yudingxinxi.setIcon(new ImageIcon("images/huiyi.bmp"));
topLabel.add(yudingxinxi); yanshi.setSize(50,20);
yanshi.setLocation(85,280);
topLabel.add(yanshi); huiyixinxi.setSize(40,20);
huiyixinxi.setLocation(140,280);
topLabel.add(huiyixinxi); tiqianjiesu.setSize(50,20);
tiqianjiesu.setLocation(195,280);
topLabel.add(tiqianjiesu); exitButton.setSize(80,20);
exitButton.setLocation(260,280);
topLabel.add(exitButton); loginButton.setSize(80,20);
loginButton.setLocation(350,280);
topLabel.add(loginButton); setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
//setSize(500,350);
setVisible(true); }// </editor-fold>
//GEN-END:initComponents /**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Dome().setVisible(true);
}
});
}
private void checkNamePwd(){
} private void exitWindow(){
System.exit(0);
} class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// 获取事件源
Object source = e.getSource();
if(source == exitButton)
{
exitWindow();
}
else if(source == loginButton)
{
checkNamePwd();
}
}
} class MyKeyListener extends KeyAdapter{
public void keyPressed(KeyEvent ke){
int code=ke.getKeyCode();
if(code==10){
checkNamePwd();
}
else if(code==27){
exitWindow();
}
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
// End of variables declaration//GEN-END:variables
}
}
我这段代码就是不会把图片显示出来 求指点swingJFrame
解决方案 »
- 一组值空的排除, 如果有重复的要合并
- No suitable driver~~~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 注意到手机上的键盘和不断变化的屏幕吗,大学知道这键盘是怎么和这么多的屏幕建立关系的呢??
- 请各位老师给我推荐一本学JAVA的书。送50分
- java 线程 同步访问。
- JDBC for oracle 8.0.5哪里下载
- JBuilder8是不是不允许Blank final reference?
- 有没有办法让Eclipse (2.1)拥有向VC7.0(.NET)那样的界面啊?
- 读一个文件,怎样不用遍历该文件,就可以知道文件的总长度?
- classpath怎么设置来着,我又忘了。
- JAVA线程问题,新手求教
- java数据结构栈题目
不是添加图片。。
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Dome extends javax.swing.JFrame { JLabel topLabel;
JLabel huiyixinxi, yudingxinxi, yanshi, tiqianjiesu;
JButton exitButton, loginButton; public void paint(Graphics g) {
super.paint(g);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(0, 0, (int) screenSize.getWidth(),
(int) screenSize.getHeight());
g.drawImage(new ImageIcon(
"C:/Users/eacfgjl/Desktop/clock.png").getImage(), 0, 0, getWidth(), getHeight(), this);// 这里换成你图片的路径
}
/** Creates new form Dome */
public Dome() {
initComponents();
} /**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
this.setBounds(0, 0, 1024, 768);
this.setResizable(false);//
topLabel = new JLabel();
topLabel.setIcon(new ImageIcon("images/mitbg.bmp"));
add(topLabel);
topLabel.setLayout(null); yudingxinxi = new JLabel("预定信息");
yudingxinxi.setForeground(Color.WHITE);
huiyixinxi = new JLabel("会议信息");
yanshi = new JLabel("会议延时");
tiqianjiesu = new JLabel("提前结束");
exitButton = new JButton("退 出");
loginButton = new JButton("登 录"); ButtonListener bListener = new ButtonListener();
// 按钮注册事件监听器
exitButton.addActionListener(bListener);
loginButton.addActionListener(bListener); MyKeyListener keylis = new MyKeyListener(); yudingxinxi.setSize(45, 20);
yudingxinxi.setLocation(40, 280);
yudingxinxi.setIcon(new ImageIcon("images/huiyi.bmp"));
topLabel.add(yudingxinxi); yanshi.setSize(50, 20);
yanshi.setLocation(85, 280);
topLabel.add(yanshi); huiyixinxi.setSize(40, 20);
huiyixinxi.setLocation(140, 280);
topLabel.add(huiyixinxi); tiqianjiesu.setSize(50, 20);
tiqianjiesu.setLocation(195, 280);
topLabel.add(tiqianjiesu); exitButton.setSize(80, 20);
exitButton.setLocation(260, 280);
topLabel.add(exitButton); loginButton.setSize(80, 20);
loginButton.setLocation(350, 280);
topLabel.add(loginButton); setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// setSize(500,350);
setVisible(true); }// </editor-fold>
// GEN-END:initComponents /**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Dome().setVisible(true);
}
});
} private void checkNamePwd() { } private void exitWindow() {
System.exit(0);
} class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
// 获取事件源
Object source = e.getSource();
if (source == exitButton) {
exitWindow();
} else if (source == loginButton) {
checkNamePwd();
}
}
} class MyKeyListener extends KeyAdapter {
public void keyPressed(KeyEvent ke) {
int code = ke.getKeyCode();
if (code == 10) {
checkNamePwd();
} else if (code == 27) {
exitWindow();
}
} // GEN-BEGIN:variables
// Variables declaration - do not modify
// End of variables declaration//GEN-END:variables
}
}
我想把这几个label 加上图片怎么办 每次加上去就会酒后把后面的覆盖掉
Image image = Toolkit.getDefaultToolkit().getImage("c:\\abc.jpg");
Icon icon = new ImageIcon(image);
jlabel.setIcon(icon);
我想把这几个label 加上图片怎么办 每次加上去就会酒后把后面的覆盖掉
Image image = Toolkit.getDefaultToolkit().getImage("c:\\abc.jpg");
Icon icon = new ImageIcon(image);
jlabel.setIcon(icon);