当前位置: 首页 > news >正文

GUI

Java的图像界面框架。

一.继承(JFrame)

import javax.swing.*;
import java.awt.*;
import java.util.Random;public class GuiDemo extends JFrame {/** public GuiDemo() throws HeadlessException{this.setTitle("我的窗体");this.setBounds(300,250,500,300);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setVisible(true);Random random = new Random(System.currentTimeMillis());// this.getContentPane().setBackground(Color.CYAN);this.getContentPane().setBackground(new Color(random.nextInt(256),random.nextInt(256),random.nextInt(256)));}*/public static void main(String[] args) throws InterruptedException {GuiDemo gui = new GuiDemo();gui.setTitle("");gui.setBounds(300,250,500,300);gui.setVisible(true);// Color[] colors = {Color.BLACK,Color.BLUE};Random ran = new Random(System.currentTimeMillis());for (;;){gui.getContentPane().setBackground(new Color(ran.nextInt(256),ran.nextInt(256),ran.nextInt(256)));Thread.sleep(100);}}
}

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;public class GuiDemo02 extends JFrame {public GuiDemo02() throws HeadlessException{this.setTitle("W");this.setBounds(300,250,500,300);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.getContentPane().setLayout(null);JButton button = new JButton("check!");JPasswordField pw = new JPasswordField();button.setBounds(300,200,100,50);this.getContentPane().add(button);this.getContentPane().add(pw);//组件(控件)button.addActionListener(new ActionListener() {//事件(动作)@Overridepublic void actionPerformed(ActionEvent e) {//响应// System.out.println("^-^");Random ran = new Random(System.currentTimeMillis());getContentPane().setBackground(new Color(ran.nextInt(256),ran.nextInt(256),ran.nextInt(256)));System.out.println(new String(pw.getPassword()));System.out.println("x:" + pw.getX());int x = pw.getX()+5;pw.setBounds(x,100,200,150);// setVisible(false);}});this.setVisible(true);}public static void main(String[] args) {new GuiDemo02();}
}

二.GUI插件

idea settings plugin

/** Created by JFormDesigner on Sat Sep 28 17:25:21 CST 2024*/package com.ffyc.form;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;/*** @author 武鑫鑫*/
public class Test extends JFrame {public Test() {initComponents();}private void pw(ActionEvent e) {// TODO add your code hereSystem.out.println("hhh");String s = new String(pw.getPassword());sp.setText(s);}private void initComponents() {// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:offbutton1 = new JButton();pw = new JPasswordField();sp = new JLabel();//======== this ========Container contentPane = getContentPane();contentPane.setLayout(null);//---- button1 ----button1.setText("check");contentPane.add(button1);button1.setBounds(new Rectangle(new Point(170, 180), button1.getPreferredSize()));//---- pw ----pw.addActionListener(e -> pw(e));contentPane.add(pw);pw.setBounds(410, 110, 200, 90);//---- sp ----sp.setText("text");contentPane.add(sp);sp.setBounds(205, 75, 155, 90);contentPane.setPreferredSize(new Dimension(1235, 840));pack();setLocationRelativeTo(getOwner());// JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on}public static void main(String[] args) {new Test().setVisible(true);}// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:offprivate JButton button1;private JPasswordField pw;private JLabel sp;// JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}


http://www.mrgr.cn/news/40410.html

相关文章:

  • C++ 语言特性04 - decltype关键字
  • 设置hive本地模式
  • JS进阶 1——作用域、解构、箭头函数
  • 【Orange Pi 5嵌入式应用编程】-用户空间UART通信
  • SupplierbasicController
  • `git restore` 和 `git checkout` 都可以用于丢弃工作区的改动,但它们有一些区别
  • UE4完整教程 UE4简介 UE4学习攻略及文件格式
  • 开放式耳机究竟是不是智商税?百元蓝牙耳机2024推荐指南
  • 低空经济时代来临,挑战和机遇详细分析
  • 64 注意力机制_by《李沐:动手学深度学习v2》pytorch版
  • Leetcode 611. 有效三角形的个数
  • 小学一年级教材识字表,写字表,笔画名称表,偏旁名称表大全,方便大家学习打印!
  • 关于malloc,calloc,realloc
  • MySQL中的InnoDB存储引擎
  • AMD CDNA™2 GPU 中的寄存器压力
  • C++模拟实现vector容器【万字模拟✨】
  • 基于51单片机的电压表电压监测proteus仿真
  • 第九讲-按钮控件QToolButton
  • 基于Springboot+Vue的基于协同过滤算法的个性化音乐推荐系统 (含源码数据库)
  • 【Python报错已解决】 WARNING: Ignoring invalid distribution