日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一文搞定Swing和Qt按钮和文本框的创建

發布時間:2023/12/18 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一文搞定Swing和Qt按钮和文本框的创建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一文搞定Swing和Qt按鈕和文本框的創建

  • Qt的截圖

java的
源碼

package com.lujun;import java.awt.Container;import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.WindowConstants;public class MyFrame extends JFrame{JButton btnButton = null;JTextField textField=null;//有參構造public MyFrame(String title) {super(title);setSize(310, 400);Container container = getContentPane();textField = new JTextField();textField.setBounds(10, 10, 100, 30);container.add(textField);btnButton = new JButton("點我試一試");btnButton.setBounds(100, 100, 120, 40);container.add(btnButton);setLayout(null);setVisible(true);setLocationRelativeTo(null);setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);setAlwaysOnTop(false);btnButton.addActionListener((e)->{testClick();});}private void testClick() {System.out.println("12312");Object[] options= {"OK","Cancel"};JOptionPane.showOptionDialog(null, textField.getText(), "提示", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);}} package com.lujun;import javax.swing.SwingUtilities; import javax.swing.UIManager;public class SwingDemo {public static void main(String[] args) {SwingUtilities.invokeLater(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubcreateGUI();}});}public static void createGUI() {try {//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");MyFrame frame = new MyFrame("Swing Demo [20210307]");} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}}}

Qt的

#ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QLineEdit> namespace Ui { class Widget; }class Widget : public QWidget {Q_OBJECTpublic slots:public:explicit Widget(QWidget *parent = 0);~Widget();public slots:void alertMessage();private:Ui::Widget *ui;QLineEdit *edit; };#endif // WIDGET_H #include "widget.h" #include "ui_widget.h" #include <QMessageBox> #include <QPushButton> #include <QDebug> #include <QLineEdit>Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget) {ui->setupUi(this);QPushButton *btn =new QPushButton;edit = new QLineEdit;edit->move(30,10);btn->setText("點我試一試");btn->setFixedSize(300,60);btn->move(QPoint(10,60));QObject::connect(btn,SIGNAL(clicked()),this,SLOT(alertMessage()) );btn->setParent(this);edit->setParent(this); } void Widget::alertMessage(){qDebug() << "123";qDebug() << edit->text(); }Widget::~Widget() {delete ui; }

語法不一樣 ,實現思路類似。

總結

以上是生活随笔為你收集整理的一文搞定Swing和Qt按钮和文本框的创建的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。