提问 了很多次的问题了。关于Java程序的,麻烦高手看一下

当我点击变大按钮的时候,图片却没有变大,请问是怎么回事。请你在修改之后在自己的电脑上运行一下,看看能不能使图片变大,再提交答案import javax.swing.*;import java.awt.*;import java.awt.event.*;public class lianxi3 extends JFrame implements ActionListener{JPanel jPanel,jPanel1;JLabel jLabel;Image image;ImageIcon imageIcon;JButton jButton;float www=1;float hhh=1;public lianxi3() { super("图片"); jPanel1=new JPanel(); jButton = new JButton("变大"); jButton.addActionListener(this); image = Toolkit.getDefaultToolkit().getImage("src/2.jpg"); jLabel = new JLabel(); jPanel = new JPanel(); jPanel1.add(jButton); imageIcon = new ImageIcon(image); jLabel.setIcon(imageIcon); jPanel.add(jLabel); this.add(jLabel, BorderLayout.NORTH); this.add(jPanel1, BorderLayout.SOUTH); this.setVisible(true); this.setSize(600, 600);} public static void main(String[] args) { new lianxi3(); } public void big(){ int width=image.getHeight(jLabel); int height=image.getWidth(jLabel); double bigger=1.25; www=(float)(www*bigger); hhh=(float)(hhh*bigger); Math mt = null; mt.pow(www,hhh); jLabel.setIcon(imageIcon); jLabel.setSize((int)www, (int)hhh); repaint(); //加上这行重绘代码试试 } public void actionPerformed(ActionEvent e) { if(e.getSource()==jButton){ big(); } } }
2026年09月25日 20:51
有3个网友回答
网友(1):

试了十分钟终于好了,你看看

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class lianxi3  extends JFrame implements ActionListener{
JPanel jPanel,jPanel1;
JLabel jLabel;
Image image;
ImageIcon  imageIcon;
JButton jButton;
float www=1;
float hhh=1;
public lianxi3() {
    super("图片");
    jPanel1=new JPanel();
    jButton = new JButton("变大");
    jButton.addActionListener(this);
    image = Toolkit.getDefaultToolkit().getImage("src/1.jpg");
    jLabel = new JLabel();
    jPanel1.add(jButton);
    imageIcon = new ImageIcon(image);
    jLabel.setIcon(imageIcon);
    this.add(jLabel, BorderLayout.NORTH); 
    this.add(jPanel1, BorderLayout.SOUTH);
    this.setVisible(true);
    this.setSize(600, 600);
}
public static void main(String[] args) {
 
new lianxi3();
}
public void big(){
        int width=imageIcon.getIconWidth();
        int height=imageIcon.getIconWidth();
        double bigger=1.25;
        www=(float)(width*bigger);
        hhh=(float)(height*bigger);
        System.out.println(www+""+hhh);
        Math.pow(www,hhh);
        image =  image.getScaledInstance((int)www, (int)hhh, Image.SCALE_DEFAULT);
        imageIcon = new ImageIcon(image);
        //jLabel.setSize((int)www, (int)hhh);
        jLabel.setIcon(imageIcon);
    }

public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
big();
}

}

}

 

网友(2):

how many?

网友(3):

看样子我得好好看看你这个怎么实现的...