小编Tim*_*ell的帖子

JComponents没有出现图片背景?

我的组件没有显示出来.我该如何解决?

码:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

public class login implements ActionListener{
    JTextField gusername;
    JTextField gpassword;
    static String username;
    static String password;

    void logini() throws IOException {
        JFrame window = new JFrame("Login");
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setSize(300, 250);
        window.setResizable(false);
        window.setVisible(true);

        JPanel mainp = new JPanel(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        window.add(mainp);

        BufferedImage myPicture = ImageIO.read(new File("c:\\bgd.png"));
        JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
        mainp.add(picLabel, c);

        c.gridx = 0;
        c.gridy = …
Run Code Online (Sandbox Code Playgroud)

java swing bufferedimage jpanel jframe

4
推荐指数
1
解决办法
4189
查看次数

JLabel根本没有出现?

所以这是我这个项目的第3个帖子,希望是最后一个.因此,当我的程序在其他类中进行数学运算时,它需要出现在JLabel中.问题是,它没有显示出来.Maby你们其中一个可以帮帮我吗?对不起,当我发布它时代码将会被删除,我无法解决它.

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class AFA {

    public void answer() {
        System.out.println("1");
        int area = (int) (AF.length * AF.width);

        String an = String.valueOf(area);

        JFrame answer = new JFrame();

        answer.setBackground(Color.yellow);
        JPanel pan2 = new JPanel();
        JLabel a = new JLabel("The answer is " + an + "We got this by multiplying the Lenght by the width");
        pan2.add(a);
        System.out.println("1");
        answer.setVisible(true);            
    }    
}
Run Code Online (Sandbox Code Playgroud)

java user-interface swing jlabel

-1
推荐指数
1
解决办法
1171
查看次数

标签 统计

java ×2

swing ×2

bufferedimage ×1

jframe ×1

jlabel ×1

jpanel ×1

user-interface ×1