我意识到这个问题已经被问过很多次了,但我觉得它没有得到正确的回答。
我想在 java gui 中使用图像作为背景
我尝试了以下方法:
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
public class worldGUI extends JFrame implements ActionListener
{
private ImageIcon world = new ImageIcon("C://Users/Hans/Documents/world/map.png");
private JLabel map = new JLabel(world);
private JButton borders = new JButton("Borders");
public worldGUI()
{
setTitle("Welcome to the World");
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,500);
setLocation(100,100);
setVisible(true);
borders.addActionListener(this);
map.add(borders);
setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我是 Java 新手,请耐心等待
我有一个从iPhone导入的csv文件,包括表情符号微笑
使用iPhone文件看起来像
但是,如果我使用从计算机打开csv文件
如何在Java中处理这些字符以获得表情符号微笑?
当我将扩展名更改为 .txt
我得到的是:
如何显示原始(iPhone)表情符号?如果我不能这样做,那么如何才能像.txt
文件一样显示微笑?
每个csv文件都有不同的表情符号笑脸!
我有2节课,
我的主类创建了一个框架,我希望另一个类向其添加内容.一些阅读arroudn告诉我,我应该使用组件来执行此操作,但是当我运行我的代码时,框架是空的.
public static void main(String[] args)
{
// create frame
JFrame frame = new JFrame();
final int FRAME_WIDTH = 800;
final int FRAME_HEIGHT = 600;
// set frame attributes
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("My Frame");
frame.setVisible(true);
Component1 Com = new Component1();
Component add = frame.add(Com);
}
Run Code Online (Sandbox Code Playgroud)
我的Component类创建了一个JLabel
public class Component1 extends JComponent {
public void paintComponent()
{
JLabel label = new JLabel("<html>Some Text</html>");
}
}
Run Code Online (Sandbox Code Playgroud)
我没有得到任何编译错误,但是我在JFrame中没有得到任何文本.
谁能解释我做错了什么?
克里斯
我已成功编译并运行以下代码,但applet窗口除了空格外什么都没显示,可能是什么问题?
我不试图在这里创建一个小程序我试图创建一个Jframe程序
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//<applet code="calc.class" width=400 height=200></applet>
public class calc extends JFrame implements ActionListener {
JFrame f1;
JPanel p1 = new JPanel();
JLabel l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15,
l16, l17, l18, l19, l20, l21, l22, l23, l24;
JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15,
b16;
JTextField t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, …
Run Code Online (Sandbox Code Playgroud) 我有一个带有 JFrame、JButton 和 JList 的简单代码,一旦单击按钮,内容应该更新:
private void btnUpdateListActionPerformed(java.awt.event.ActionEvent evt) {
//A default list model containing two strings is created.
DefaultListModel listModel = new DefaultListModel();
listModel.addElement("hello");
listModel.addElement("bye");
//The JList is updated so that it contains the strings of the default list model.
list = new JList(listModel);
}
Run Code Online (Sandbox Code Playgroud)
但是,按下按钮后什么也没有发生;该列表保留其原始值:
如何解决此问题,以便列表根据需要更新?
我想实现这种外观并尝试相应地设置 JPanel 组件,但当我运行应用程序时,我看到了不同的位置。这就是我正在寻找的外观:
首先,顺序不正确,其次,项目之间没有空格,所以总的来说,这不是我想要的。如何修复它以使其看起来与我第一次添加的图像相似?我的代码:
package Lab5;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
public class FontDesigner extends JFrame {
public FontDesigner() {
// JFrame
setSize(400, 400);
setTitle("Font Changer");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// String
JLabel text = new JLabel("Change Me");
text.setFont(new Font("Arial", 1, 28));
// Radio Button
JRadioButton button1 = new JRadioButton("Small");
JRadioButton button2 = new JRadioButton("Medium");
JRadioButton button3 = new JRadioButton("Large");
ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(button1);
radioGroup.add(button2);
radioGroup.add(button3);
/*
* if (button1.isSelected()) {
* text.setSize(1);
* }
*/
// Combo Box …
Run Code Online (Sandbox Code Playgroud) 我的代码的一部分有问题.我已经在这方面工作了很长时间,我很累,错过了一些简单的事情.我需要一个文本框来输入JFrame的新标题,一个显示"设置新名称"的按钮和一个"退出按钮.有人可以查看这些代码并给我一些信息,这样我就可以上床了.谢谢您
//Good One
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
public class Pool {
public static void main(String[] args) {
new poolCalc();
}
}
class poolCalc extends JFrame {
private static final long serialVersionUID = 1L;
public static final double MILLIMETER = 1;
public static final double METER = 1000 * MILLIMETER;
public static final double INCH = 25.4 * MILLIMETER;
public static final double FOOT = 304.8 * MILLIMETER;
public static final double YARD …
Run Code Online (Sandbox Code Playgroud)