各种编程语言的按钮输入框
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                各种编程语言的按钮输入框
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                各種編程語言輸入框按鈕的實現(xiàn)
本人有個需求,一個頁面,有按鈕,輸入框,一個顯示框,用戶點擊按鈕會彈出輸入框內(nèi)容,并且顯示在文本標(biāo)簽里面。我將使用以下技術(shù)逐個突破,各個擊破。win32 api編程,qt,java swing,swift,objective-c,swiftUI,Android,PHP,asp dao net web,winform,wpf,devExpress,mfc,js,golang,vb等實現(xiàn)
 swiftUI
 
swift代碼
// // ViewController.swift // DemoTestField1 // // Created by 魯軍 on 2021/3/21. //import UIKitclass ViewController: UIViewController {@IBOutlet weak var lbl: UILabel!@IBOutlet weak var text: UITextField!override func viewDidLoad() {super.viewDidLoad()lbl.text = ""}@IBAction func click(_ sender: Any) {lbl.text = text.text} }oc代碼
// ViewController.m // ocTestFileld // Created by 魯軍 on 2021/3/21. #import "ViewController.h"@interface ViewController () - (IBAction)click:(id)sender; @property (weak, nonatomic) IBOutlet UILabel *lbl; @property (weak, nonatomic) IBOutlet UITextField *textField; @end@implementation ViewController - (void)viewDidLoad {[super viewDidLoad];self.lbl.text = @""; }- (IBAction)click:(id)sender {self.lbl.text = self.textField.text; } @endjava代碼
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 [20210321]");} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}}} package com.lujun;import java.awt.Container;import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.WindowConstants;public class MyFrame extends JFrame{JButton btnButton = null;JTextField textField=null;JLabel jLabel=null;//有參構(gòu)造public MyFrame(String title) {super(title);setSize(310, 270);Container container = getContentPane();textField = new JTextField();textField.setBounds(100, 10, 150, 30);container.add(textField);btnButton = new JButton("點擊");btnButton.setBounds(100, 100, 120, 40);container.add(btnButton);jLabel = new JLabel();jLabel.setBounds(100, 50, 120, 40);container.add(jLabel);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]);jLabel.setText(textField.getText());}} using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace TestShowMessage1 {public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){this.label1.Text = this.textBox1.Text;MessageBox.Show(this.textBox1.Text);}} }Qt
#include "widget.h" #include "ui_widget.h" #include <QMessageBox>Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget) {ui->setupUi(this); }Widget::~Widget() {delete ui; }void Widget::on_pushButton_clicked() {ui->label->setText(ui->lineEdit->text());QMessageBox::warning(this,"提示",ui->lineEdit->text()); }MFC源碼
 
需要添加變量(控件變量) 否則代碼報錯 點擊事件的函數(shù)
 
win 32 API編程
#include <Windows.h> #include<stdio.h> #include<string.h> #include <iostream> using namespace std; #pragma warning(disable:4996) HWND hEdit1; HWND hEdit2; HWND hLabel2; // 入口函數(shù) 是WinMain LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void CALLBACK MyTimeProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD Time);char* TCHARToChar(const TCHAR* pTchar);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int mCmdShow) {TCHAR szAppClassName[] = TEXT("dajun");WNDCLASS wc = { 0 }; //結(jié)構(gòu)體變量wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wc.hCursor = LoadCursor(NULL, IDC_ARROW);wc.hInstance = hInstance;wc.lpfnWndProc = WindowProc;wc.lpszClassName = szAppClassName;wc.style = CS_HREDRAW | CS_VREDRAW;RegisterClass(&wc); //注冊//創(chuàng)建窗口HWND hWnd = CreateWindow(szAppClassName,TEXT("Desgin By Johnson2021.3.22"),WS_OVERLAPPEDWINDOW,400, 200,380, 240,NULL, //父窗口句柄NULL, //菜單句柄hInstance, //應(yīng)用程序?qū)嵗浔?/span>NULL);ShowWindow(hWnd, SW_SHOW);UpdateWindow(hWnd);MSG msg;while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return 0; } LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {static HFONT hFont; //邏輯字體static HBRUSH hBrush; //畫刷switch (uMsg){case WM_KEYDOWN:switch (wParam){case VK_UP:MessageBox(NULL, L"xia jian", L"Tips", MB_OK);break;default:break;}case WM_CREATE:{LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;hEdit1 = CreateWindow(L"ediT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER,30, 30,200,24,hWnd,(HMENU)110,pcs->hInstance,NULL);hEdit2 = CreateWindow(L"ediT", L"這是編輯框3", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL | ES_NOHIDESEL,30, 80,200,100,hWnd,(HMENU)112,pcs->hInstance,NULL);hLabel2 = CreateWindow(L"static", L"這是靜態(tài)文本區(qū)域", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL | ES_NOHIDESEL,20, 5,200,18,hWnd,(HMENU)118,pcs->hInstance,NULL);//創(chuàng)建畫刷hBrush = CreateSolidBrush(RGB(0x41, 0x96, 0x4F));//創(chuàng)建邏輯字體hFont = CreateFont(-14/*高*/, -7/*寬*/, 0, 0, 700 /*700表示粗體*/,FALSE/*斜體?*/, FALSE/*下劃線?*/, FALSE/*刪除線?*/, DEFAULT_CHARSET,OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,FF_DONTCARE, TEXT("微軟雅黑"));//創(chuàng)建靜態(tài)文本框控件//設(shè)置控件的字體SendMessage(hLabel2, WM_SETFONT, (WPARAM)hFont, NULL);HWND hBtn = CreateWindow(L"button", L"點擊我", WS_CHILD | WS_VISIBLE | WS_BORDER,250, 30,80,30,hWnd,(HMENU)111,pcs->hInstance,NULL);SendMessage(hEdit2, EM_SETSEL, 0, 0);SendMessage(hEdit2, WM_CUT, 0, 0);SendMessage(hEdit2, EM_UNDO, 0, 0);return 0;}break;case WM_COMMAND:{int wmId = LOWORD(wParam);WORD code = HIWORD(wParam);HWND hCtrl = (HWND)lParam;if (wmId == 111 && code == BN_CLICKED){TCHAR buf[64] = { 0 };GetWindowText(hEdit1, buf, sizeof(buf));SetWindowText(hEdit2, buf);SetWindowText(hLabel2, buf);MessageBox(NULL, buf, L"tips", MB_OK);}}break;case WM_CLOSE:DestroyWindow(hWnd);break;case WM_DESTROY:PostQuitMessage(0);break;default:break;}return DefWindowProc(hWnd, uMsg, wParam, lParam); } char* TCHARToChar(const TCHAR* pTchar) {char* pChar = NULL; #ifdef _UNICODEint nLen = wcslen(pTchar) + 1;pChar = new char[nLen * 2];WideCharToMultiByte(CP_ACP, 0, pTchar, nLen, pChar, 2 * nLen, NULL, NULL); #elseint nLen = strlen(pTchar) + 1;pChar = new char[nLen];memcpy(pChar, pTchar, nLen * sizeof(char)); #endifreturn pChar; }實現(xiàn)效果:
 
 vb程序代碼
實現(xiàn)效果
 
 python 實現(xiàn)源碼
實現(xiàn)效果
 
 原生javascript 實現(xiàn)
JQuery寫法:
<!DOCTYPE html> <html><head><meta charset="utf-8" /><title>test</title><style type="text/css">*{margin: 0;padding: 0;}#div1{width: 500px;height: 300px;border: 1px solid #000;margin: 100px;padding: 50px;}</style><script src="jquery.js" type="text/javascript"></script><script type="text/javascript">$(function(){//第一種寫法$("#btn1").click(function(){var txt = $("#txt1").val()$("#sp1").html(txt)//alert(txt)});//第二種寫法$("#btn1").on('click',function(){//alert("456")var text1 = $("#txt1").val()$("#sp1").html(text1)});});</script></head><body><div id="div1"><span id="sp1" style="margin: 20px;"></span><br /><input type="text" style="margin: 20px;" id="txt1" /><br /><input type="button" id="btn1" value="點擊" style="margin: 20px;" /><br /></div></body> </html>
 wpf寫法:
安卓待續(xù)… 2021.3.22 from Shanghai By Johnson
總結(jié)
以上是生活随笔為你收集整理的各种编程语言的按钮输入框的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: AFN框架和SDWebImage框架的上
- 下一篇: AMD发布APPML源码,构建clMat
