java 文本区域_java-能够从其他类访问文本区域

我如何才能从main()运行此函数以构建gui,然后使用其他地方的代码来处理按钮单击并从文本字段检索输入?

package main;

import javax.swing.*;

import java.awt.*;

public class Gui {

public static void mainGUI() {

UIManager.put("swing.boldMetal", Boolean.FALSE);

java.net.URL imgApp = ClassLoader.getSystemResource("res/app.png");

JFrame mainWin = new JFrame("jIRC");

mainWin.setSize(1024, 720);

mainWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainWin.setIconImage(new ImageIcon(imgApp).getImage());

Container panel = mainWin.getContentPane();

panel.setLayout(null);

JTextArea inputBox = new JTextArea();

inputBox.setSize(300, 100);

inputBox.setLocation(500, 250);

JButton sendButton = new JButton();

sendButton.setText("Send");

sendButton.setFont(new Font("Helvetica", Font.ITALIC, 16));

sendButton.setSize(72, 32);

sendButton.setLocation(500, 500);

panel.add(inputBox);

panel.add(sendButton);

mainWin.setVisible(true);

}

}

这是我的带有主要功能的课程:

public class Run{

public static void main(String[] args) {

main.Debug.startupDebug();

main.Gui.mainGUI();

}

}

我该如何将我的一些代码放置在非静态字段中?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值