Java程序:
import javaawtBorderLayout;import javaawteventActionEvent;
import javaawteventActionListener;
import javautilArrays;
import javautilRandom;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJTextArea;
public class Main extends JFrame implements ActionListener {
protected JButton btnGenerate;
protected JTextArea txtResult;
public static void main(String[] args){
new Main();
}
public Main() {
super("随机数成品器");
initComponent();
}
public void initComponent() {
btnGenerate = new JButton("生成");
txtResult = new JTextArea(20, 50);
thissetLayout(new BorderLayout());
thisadd("North", btnGenerate);
thisadd("Center", txtResult);
thissetSize(300, 450);
thissetVisible(true);
thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
btnGenerateaddActionListener(this);
}
@Override
public void actionPerformed(ActionEvent arg0) {
JButton btn = (JButton) arg0getSource();
if(btn == btnGenerate) {
int[] arr = getRandom(1, 100, 20);
Arrayssort(arr);
StringBuilder str = new StringBuilder();
for(int i=0; i<arrlength-1; i++) {
strappend(arr[i] + "\n");
}
strappend(arr[arrlength-1]);
txtResultsetText(strtoString());
}
}
//返回minmax之间的size个随机数
public static int[] getRandom(int min, int max, int size) {
Random rand = new Random();
int[] arr = new int[size];
for(int i=0; i<arrlength; i++) {
arr[i] = randnextInt(max);
}
return arr;
}
}
运行测试:
题目中说明中的第一步:偶数2,奇数1 但是示例中的员工等级是偶数单乘的是1,我的代码中员工等级的处理方式和员工号一致,如果需要调整,在Calc(string xx)方法中注释的else位置修改。
中是窗口截图。代码如下:
namespace Calc
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private SystemComponentModelIContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
componentsDispose();
}
baseDispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
thistxtNumber = new SystemWindowsFormsTextBox();
thistxtPwd = new SystemWindowsFormsTextBox();
thistxtLevel = new SystemWindowsFormsTextBox();
thistxtValCode = new SystemWindowsFormsTextBox();
thislabel1 = new SystemWindowsFormsLabel();
thislabel2 = new SystemWindowsFormsLabel();
thislabel3 = new SystemWindowsFormsLabel();
thislabel4 = new SystemWindowsFormsLabel();
thislabel5 = new SystemWindowsFormsLabel();
thistxtInput = new SystemWindowsFormsTextBox();
thisSuspendLayout();
//
// txtNumber
//
thistxtNumberLocation = new SystemDrawingPoint(102, 68);
thistxtNumberName = "txtNumber";
thistxtNumberReadOnly = true;
thistxtNumberSize = new SystemDrawingSize(126, 21);
thistxtNumberTabIndex = 0;
//
// txtPwd
//
thistxtPwdLocation = new SystemDrawingPoint(102, 105);
thistxtPwdName = "txtPwd";
thistxtPwdPasswordChar = '';
thistxtPwdReadOnly = true;
thistxtPwdSize = new SystemDrawingSize(126, 21);
thistxtPwdTabIndex = 0;
//
// txtLevel
//
thistxtLevelLocation = new SystemDrawingPoint(102, 136);
thistxtLevelName = "txtLevel";
thistxtLevelReadOnly = true;
thistxtLevelSize = new SystemDrawingSize(126, 21);
thistxtLevelTabIndex = 0;
//
// txtValCode
//
thistxtValCodeLocation = new SystemDrawingPoint(102, 173);
thistxtValCodeName = "txtValCode";
thistxtValCodeReadOnly = true;
thistxtValCodeSize = new SystemDrawingSize(126, 21);
thistxtValCodeTabIndex = 0;
//
// label1
//
thislabel1AutoSize = true;
thislabel1Location = new SystemDrawingPoint(55, 71);
thislabel1Name = "label1";
thislabel1Size = new SystemDrawingSize(29, 12);
thislabel1TabIndex = 4;
thislabel1Text = "工号";
//
// label2
//
thislabel2AutoSize = true;
thislabel2Location = new SystemDrawingPoint(55, 108);
thislabel2Name = "label2";
thislabel2Size = new SystemDrawingSize(29, 12);
thislabel2TabIndex = 5;
thislabel2Text = "密码";
//
// label3
//
thislabel3AutoSize = true;
thislabel3Location = new SystemDrawingPoint(55, 139);
thislabel3Name = "label3";
thislabel3Size = new SystemDrawingSize(29, 12);
thislabel3TabIndex = 6;
thislabel3Text = "级别";
//
// label4
//
thislabel4AutoSize = true;
thislabel4Location = new SystemDrawingPoint(55, 176);
thislabel4Name = "label4";
thislabel4Size = new SystemDrawingSize(41, 12);
thislabel4TabIndex = 7;
thislabel4Text = "验证码";
//
// label5
//
thislabel5AutoSize = true;
thislabel5Location = new SystemDrawingPoint(55, 31);
thislabel5Name = "label5";
thislabel5Size = new SystemDrawingSize(29, 12);
thislabel5TabIndex = 8;
thislabel5Text = "工号";
//
// txtInput
//
thistxtInputLocation = new SystemDrawingPoint(102, 28);
thistxtInputName = "txtInput";
thistxtInputSize = new SystemDrawingSize(126, 21);
thistxtInputTabIndex = 1;
thistxtInputLeave += new SystemEventHandler(thistxtInput_Leave);
thistxtInputKeyPress += new SystemWindowsFormsKeyPressEventHandler(thistxtInput_KeyPress);
//
// Form1
//
thisAutoScaleDimensions = new SystemDrawingSizeF(6F, 12F);
thisAutoScaleMode = SystemWindowsFormsAutoScaleModeFont;
thisClientSize = new SystemDrawingSize(263, 241);
thisControlsAdd(thistxtInput);
thisControlsAdd(thislabel5);
thisControlsAdd(thislabel4);
thisControlsAdd(thislabel3);
thisControlsAdd(thislabel2);
thisControlsAdd(thislabel1);
thisControlsAdd(thistxtValCode);
thisControlsAdd(thistxtLevel);
thisControlsAdd(thistxtPwd);
thisControlsAdd(thistxtNumber);
thisName = "Form1";
thisText = "Form1";
thisResumeLayout(false);
thisPerformLayout();
}
#endregion
private SystemWindowsFormsTextBox txtNumber;
private SystemWindowsFormsTextBox txtPwd;
private SystemWindowsFormsTextBox txtValCode;
private SystemWindowsFormsLabel label1;
private SystemWindowsFormsLabel label2;
private SystemWindowsFormsLabel label3;
private SystemWindowsFormsLabel label4;
private SystemWindowsFormsTextBox txtLevel;
private SystemWindowsFormsLabel label5;
private SystemWindowsFormsTextBox txtInput;
}
}
using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemLinq;
using SystemText;
using SystemWindowsForms;
namespace Calc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
txtInputFocus();
}
private void txtInput_Leave(object sender, EventArgs e)
{
string content = txtInputTextTrim();
Calc(content);
}
private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
{
int charInt = (int)eKeyChar;
if (charInt == 8 || charInt ==13)
{
string content = txtInputTextTrim();
Calc(content);
}
}
private void Calc(string content)
{
if (stringIsNullOrEmpty(content))
{
MessageBoxShow("请输入工号。");
txtInputSelectAll();
return;
}
if (contentLength < 11)
{
MessageBoxShow("输入的工号格式不正确。");
txtInputSelectAll();
return;
}
string number = contentSubstring(0, 6);
string pwd = contentSubstring(7, 4);
string level = content[10]ToString();
txtNumberText = number;
txtPwdText = pwd;
txtLevelText = level;
//计算验证码
char[] numberChar = numberToCharArray();
int result = 0;
for (int i = 0; i < numberCharLength + 1; i++)
{
if (i < numberCharLength)
{
int calcNumber = intParse(numberChar[i] + "");
int element = (calcNumber) % 2 == 0 calcNumber 2 : calcNumber;
if (element > 10)
element = intParse(elementToString()[1] + "") + 1;
result += element;
}
else //级别校验,级别值为1 2 3 4 9按照规则计算结果不会超过10
{
int levelInt = intParse(level);
result += levelInt % 2 == 0 levelInt 2 : levelInt;
}
}
result = CalcUntilSingleNumber(result);
txtValCodeText = result + "";
}
private int CalcUntilSingleNumber(int number)
{
int result = 0;
string resultString = numberToString();
if (resultStringLength > 1)
{
char[] stringChar = resultStringToCharArray();
foreach (char item in stringChar)
{
result += intParse(item + "");
}
if (result >= 10)
result = CalcUntilSingleNumber(result);
}
else
{
result = number;
}
return result;
}
}
}
控件如图,由左到右,由上到下,分别命名为b1,b2,b3,b4,l1,l2,button1,button2,timer1,timer2
timer1与timer2的Enabled的属性默认为false,Interval默认为1000,
后代代码如下
bool Isopen = false;
int b2Times = 0;
int b3Times = 0;
int onebreak = 0;
private void b1_Click(object sender, EventArgs e)
{
Isopen = true;
if (onebreak==1)
{
timer1Enabled = true;
}
if (onebreak==2)
{
timer2Enabled = true;
}
}
private void b2_Click(object sender, EventArgs e)
{
if (onebreak==0)
{
if (Isopen == false)
{
return;
}
b2Times += 1;
if (b2Times >= b3Times)
{
l1BackColor = ColorRed;
l2BackColor = ColorWhite;
}
}
}
private void b3_Click(object sender, EventArgs e)
{
if (onebreak==0)
{
if (Isopen == false)
{
return;
}
b3Times += 1;
if (b3Times >= b2Times)
{
l1BackColor = ColorWhite;
l2BackColor = ColorRed;
}
}
}
private void b4_Click(object sender, EventArgs e)
{
b3Times = 0;
b2Times = 0;
Isopen = false;
l1BackColor=ColorWhite;
l2BackColor = ColorWhite;
timer1Enabled = false;
timer2Enabled = false;
}
private void button1_Click(object sender, EventArgs e)
{
if (onebreak == 1)
{
button1Text = "第一个灯泡坏掉";
onebreak = 0;
timer1Enabled = false;
button2Enabled = true;
return;
}
onebreak = 1;
l2BackColor = ColorWhite;
button1Text = "修好它";
button2Enabled = false;
if (Isopen==false)
{
return;
}
timer2Enabled = false;
timer1Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
if (onebreak == 2)
{
button2Text = "第二个灯泡坏掉";
onebreak = 0;
timer2Enabled = false;
button1Enabled = true;
return;
}
onebreak = 2;
l1BackColor = ColorWhite;
button2Text = "修好它";
button1Enabled = false;
if (Isopen == false)
{
return;
}
timer2Enabled = true;
timer1Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
if ( l1BackColor != ColorRed)
{
l1BackColor = ColorRed;
return;
}
if (l1BackColor != ColorWhite)
{
l1BackColor = ColorWhite;
return;
}
}
private void timer2_Tick(object sender, EventArgs e)
{
if (l2BackColor != ColorRed)
{
l2BackColor = ColorRed;
return;
}
if (l2BackColor != ColorWhite)
{
l2BackColor = ColorWhite;
return;
}
}
比如说
三个窗口
主窗口Form1
饼图窗口
Form2
柱状图Form3
thisarray={1,2,3,5,12,23,12};
From2、Form3定义一个数组
用于接收From1的数值
Form2
f2=new
Form2();
f2array=thisarray;
f2show();//Form2的Load方法写入
通过array生成饼图
From3的方法同Form2
Form3
f3=new
Form3();
f3array=thisarray;
f3show();
如果要写记分牌最好使用的工具visualstudio2010(推荐)微软官网有可以下载中文版。
如果只用c语言的话,就要用win32api编写。
简介:
C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。
尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。
特有特点:
C语言是一个有结构化程序设计、具有变量作用域(variablescope)以及递归功能的过程式语言。
C语言传递参数均是以值传递(passbyvalue),另外也可以传递指针(apointerpassedbyvalue)。
不同的变量类型可以用结构体(struct)组合在一起。
只有32个保留字(reservedkeywords),使变量、函数命名有更多d性。
部份的变量类型可以转换,例如整型和字符型变量。
通过指针(pointer),C语言可以容易的对存储器进行低级控制。
预编译处理()让C语言的编译更具有d性。
Private Sub Form_Load()
MeCaption = "显示与删除"
MeMaxButton = False '或者=0
cmd1Caption = "显示"
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MeCls
End Sub
Private Sub Cmd1_Click()
Print "Visual Basic,Visual Basic,"
End Sub
以上就是关于java设计一个窗体应用程序单击生成按钮要求产生100以内20个随机整数,将全部的内容,包括:java设计一个窗体应用程序单击生成按钮要求产生100以内20个随机整数,将、c#windows窗体应用的一个程序设计。希望写出代码来。验证代码后采纳。、用C#语言编写windows窗体应用程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)