java编写一个图形界面程序

java编写一个图形界面程序,第1张

import javaawt;

import javaawtevent;

import javautil;

import javaxswing;

import javaxswingborderBorder;

class MainFrame extends JFrame {

private static final long serialVersionUID = 1L;

private Map<String, Integer> sizes = new HashMap<String, Integer>();

private Map<String, Integer> styles = new HashMap<String, Integer>();

private Map<String, Integer> toppings = new HashMap<String, Integer>();

public MainFrame() {

sizesput("Extra Large", 10);

sizesput("Large", 8);

sizesput("Medium", 5);

sizesput("Small", 3);

stylesput("Deep Dish", 20);

stylesput("Regular", 10);

stylesput("Thin Crust", 5);

stylesput("Chicago", 3);

toppingsput("Cheese", 8);

toppingsput("Tomato", 7);

toppingsput("Peppers", 6);

toppingsput("Peperoni", 5);

thissetTitle("布局及事件处理");

thissetSize(450, 350);

thissetLayout(new BorderLayout());

thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

JLabel lblTitle = new JLabel();

lblTitlesetText("Pizzeria Juno");

lblTitlesetFont(new Font("宋体", FontBOLD, 36));

lblTitlesetHorizontalAlignment(SwingConstantsCENTER);

thisadd("North", lblTitle);

JPanel bodyPanel = new JPanel();

bodyPanelsetLayout(new GridLayout(2, 1));

thisadd("Center", bodyPanel);

JPanel listPanel = new JPanel();

listPanelsetLayout(new GridLayout(1, 3));

listPanelsetSize(200, 200);

bodyPaneladd(listPanel);

Border lineBorder = BorderFactorycreateLineBorder(ColorBLACK);

JPanel sizePanel = new JPanel();

sizePanelsetLayout(new BorderLayout());

listPaneladd(sizePanel);

JLabel sizeTitle = new JLabel();

sizeTitlesetText("Sizes");

sizePaneladd("North", sizeTitle);

JList sizeList = new JList(sizeskeySet()toArray());

sizeListsetSize(100, 100);

sizeListsetBorder(lineBorder);

sizeListsetSelectionMode(ListSelectionModelSINGLE_SELECTION);

sizePaneladd(sizeList);

JPanel stylePanel = new JPanel();

stylePanelsetLayout(new BorderLayout());

listPaneladd(stylePanel);

JLabel styleTitle = new JLabel();

styleTitlesetText("Styles");

stylePaneladd("North", styleTitle);

JList styleList = new JList(styleskeySet()toArray());

styleListsetSize(100, 100);

styleListsetBorder(lineBorder);

styleListsetSelectionMode(ListSelectionModelSINGLE_SELECTION);

stylePaneladd(styleList);

JPanel toppingPanel = new JPanel();

toppingPanelsetLayout(new BorderLayout());

listPaneladd(toppingPanel);

JLabel toppingTitle = new JLabel();

toppingTitlesetText("Toppings");

toppingPaneladd("North", toppingTitle);

JList toppingList = new JList(toppingskeySet()toArray());

toppingListsetSize(100, 100);

toppingListsetBorder(lineBorder);

toppingPaneladd(toppingList);

JTextArea txtResult = new JTextArea();

txtResultsetEditable(false);

bodyPaneladd(txtResult);

JPanel bottomPanel = new JPanel();

bottomPanelsetLayout(new GridLayout(1, 3));

thisadd("South", bottomPanel);

JLabel label1 = new JLabel("Click to complete order");

bottomPaneladd(label1);

JButton btnRingUp = new JButton("Ring up");

btnRingUpaddActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

if(sizeListgetSelectedValue() == null) {

JOptionPaneshowMessageDialog(MainFramethis, "Please select size");

return;

}

if(styleListgetSelectedValue() == null) {

JOptionPaneshowMessageDialog(MainFramethis, "Please select style");

return;

}

if(toppingListgetSelectedValue() == null) {

JOptionPaneshowMessageDialog(MainFramethis, "Please select topping");

return;

}

float total = 0;

String size = sizeListgetSelectedValue()toString();

total += sizesget(size);

String style = styleListgetSelectedValue()toString();

total += stylesget(style);

String result = size + " Pizza, " + style + " Style";

Object[] toppings = toppingListgetSelectedValues();

for(Object topping : toppings) {

result += "\n  +" + toppingtoString();

total += MainFramethistoppingsget(toppingtoString());

}

result += "\n  Total: " + total;

txtResultsetText(result);

}

});

bottomPaneladd(btnRingUp);

JButton btnQuit = new JButton("Quit");

btnQuitaddActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

MainFramethisdispose();

}

});

bottomPaneladd(btnQuit);

}

}

public class App {

public static void main(String[] args) {

MainFrame mainFrame = new MainFrame();

mainFramesetVisible(true);

}

}

首先是电脑的java模拟器。在做测试以前在搜索引擎中将两个模拟器下载下来。自然是下载安全无毒的java模拟器。电脑使用的是exe文件但是常以rar打包。安卓智能机是apk文件。

我使用的java模拟器是个绿色软件,也就是说无需安装。解压压缩包后打开文件夹。找到主运行文件点击运行。

在程序主界面点击文件。选择载入jar文件。jar就是java数据文件java压缩包。山寨机时代大家经常接触。

我尝试加载一个很久前的javaQQ。载入之后自动运行程序。很熟悉的qq登陆界面。也尝试登陆了一下,果然无法登陆,没有在进行其他的检测。软件还提供了一些其他的功能诸如截图之类的比较实用。

如果是apk文件则先将其安装至手机安装成功之后再运行该应用。

软件界面空荡荡的,点击选项按钮,扫描内存卡。这时候软件会扫描手机内存卡中的jar文件。并返回搜索结果

点击该结果载入jar文件。这个jar就进入虚拟机管理列表中了。以后运行就可以直接在列表中运行。点击运行该jar等待程序执行即可。由于手机低配一时没有运行出结果。所以最终效果图就不贴了。

回答于 2018-08-02

向ta提问

苹果ios-京东手机,超长续航,玩转世界!

苹果(Apple) Apple 苹果 iPhone 11 手机通4G手机 移动联通电信ios 简装版 ** 128G

¥4299 元

苹果(Apple) Apple 苹果 iPhone 11 手机通4G手机 移动联通电信ios 简装版 ** 64G

¥3899 元

苹果(Apple) Apple 苹果 iPhone 11 手机通4G手机 移动联通电信ios 简装版 白色 128G

¥4299 元

京东广告

云手机官版-新用户8折-价格更低-免费下载

根据文中提到的安卓模拟器为您推荐

「红手指云手机」云手机千万级,手游玩家必备神器,打副本,做日常主线任务一键自动 *** 作。批量挂机,无限多开,同屏预览,解放双手

南京展智电子商务广告

java应用开发-猪八戒网 专业软件开发公司 多年开发经验

java应用开发专业软件开发公司+软件开发团队 价格更实惠 技术更成熟!猪八戒网为各大互联网行业提供软件开发解决方案 轻松解决用户需求!

广告

教程,如何用安卓手机装模拟器运行JAVA游戏

视频回答

码农掌叔

7浏览

更多专家

如何用java程序 *** 作安卓模拟器

专家1对1在线解答问题

5分钟内响应 | 万名专业答主

马上提问

最美的花火 咨询一个电子数码问题,并发表了好评

lanqiuwangzi 咨询一个电子数码问题,并发表了好评

garlic 咨询一个电子数码问题,并发表了好评

1888493 咨询一个电子数码问题,并发表了好评

篮球大图 咨询一个电子数码问题,并发表了好评

动物乐园 咨询一个电子数码问题,并发表了好评

AKA 咨询一个电子数码问题,并发表了好评

android程序怎么在模拟器运行

您好,推荐你用叶子猪android模拟器。1百度叶子猪下载。2在模拟器浏览器页面上输入你要得软件。3下载即可

java编写图形界面需要用到swing等组件,可以在eclipse中安装windowbuilder来开发窗体,自动生成窗体代码,然后自己再根据需要修改,如:

package mainFrame;

import javaawtEventQueue;

import javaawteventMouseAdapter;

import javaawteventMouseEvent;

import javaxswingImageIcon;

import javaxswingJButton;

import javaxswingJCheckBox;

import javaxswingJFrame;

import javaxswingJLabel;

import javaxswingJPanel;

import javaxswingJPasswordField;

import javaxswingJTextField;

import javaxswingSwingConstants;

import javaxswingUIManager;

import javaxswingUnsupportedLookAndFeelException;

import javaxswingborderEmptyBorder;

public class Mian_login extends JFrame {

private JPanel contentPane;

private JTextField text_LoginName;

private JPasswordField Login_password;

/

Launch the application

/

public static void main(String[] args) {

EventQueueinvokeLater(new Runnable() {

@Override

public void run() {

try {

Mian_login frame = new Mian_login();

framesetVisible(true);

} catch (Exception e) {

eprintStackTrace();

}

}

});

}

/

Create the frame

/

public Mian_login() {

setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

setBounds(500, 200, 443, 300);

setResizable(false);

setTitle("登 录");

/获取系统按钮样式/

String lookAndFeel = UIManagergetSystemLookAndFeelClassName();

try {

UIManagersetLookAndFeel(lookAndFeel);

} catch (ClassNotFoundException e1) {

e1printStackTrace();

} catch (InstantiationException e1) {

e1printStackTrace();

} catch (IllegalAccessException e1) {

e1printStackTrace();

} catch (UnsupportedLookAndFeelException e1) {

e1printStackTrace();

}

contentPane = new JPanel();

contentPanesetBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

contentPanesetLayout(null);

JPanel panel = new JPanel();

panelsetOpaque(false);

panelsetBounds(0, 0, 434, 272);

contentPaneadd(panel);

panelsetLayout(null);

JButton btn_Login = new JButton("\u767B\u5F55");

btn_LoginaddMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

}

});

btn_LoginsetBounds(88, 195, 70, 23);

paneladd(btn_Login);

JButton btn_cancel = new JButton("\u53D6\u6D88");

btn_canceladdMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

dispose();

}

});

btn_cancelsetBounds(268, 195, 70, 23);

paneladd(btn_cancel);

JLabel lblNewLabel_name = new JLabel("\u7528\u6237\u540D");

lblNewLabel_namesetHorizontalAlignment(SwingConstantsCENTER);

lblNewLabel_namesetOpaque(true);

lblNewLabel_namesetBounds(88, 48, 70, 23);

paneladd(lblNewLabel_name);

JLabel lblNewLabel_passwd = new JLabel("\u5BC6\u7801");

lblNewLabel_passwdsetHorizontalAlignment(SwingConstantsCENTER);

lblNewLabel_passwdsetOpaque(true);

lblNewLabel_passwdsetBounds(88, 102, 70, 23);

paneladd(lblNewLabel_passwd);

JCheckBox chckbx_remember = new JCheckBox("\u8BB0\u4F4F\u5BC6\u7801");

chckbx_remembersetBounds(102, 150, 84, 23);

paneladd(chckbx_remember);

text_LoginName = new JTextField();

text_LoginNamesetBounds(182, 48, 156, 23);

paneladd(text_LoginName);

text_LoginNamesetColumns(10);

Login_password = new JPasswordField();

Login_passwordsetBounds(182, 102, 156, 23);

paneladd(Login_password);

JCheckBox chckbx_AutoLogin = new JCheckBox("\u81EA\u52A8\u767B\u5F55");

chckbx_AutoLoginsetBounds(233, 150, 84, 23);

paneladd(chckbx_AutoLogin);

JLabel Label_background = new JLabel("");

Label_backgroundsetIcon(new ImageIcon("E:\\JAVA_workplace\\0002-\u754C\u9762\u8BBE\u8BA1\\images\\background3jpg"));

Label_backgroundsetBounds(0, 0, 437, 272);

contentPaneadd(Label_background);

}

}

以上就是关于java编写一个图形界面程序全部的内容,包括:java编写一个图形界面程序、java桌面应用程序可以控制模拟器吗安卓、怎样用java编写图形界面的Application程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zz/9489159.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存