java代码怎么写显示多个选择
1.在java中怎样实现多个界面之间的切换
一般在界面类中,因为界面类不是MIDlet的子类,所以需要获得Display对象有两个方法:
1、传递MIDlet类型的对象
2、传递Display类型的对象
下面就以传递Display对象为例来实现在界面类中进行切换。下面的程序为了简单起见,以两个Canvas界面为例来演示实际的传递,高级界面和这个使用完全一样。
MIDlet中的代码实现:
Display display;
public MyMIDlet(){
display = Display.getDisplay(this);
//创建需要显示的界面对象
FirstCanvas fc = new FirstCanvas(display);
//显示界面
display.setCurrent(fc);
}
第一个界面类的代码实现:
public class FirstCanvas extends Canvas{
Display display;
public FirstCanvas(Display display){
this.display = display;
}
/**绘制方法*/
public void paint(Graphics g){
g.drawString(“第一个界面”,30,40,Graphics.TOP | Graphics.LEFT);
}
/**事件处理*/
public void keyPressed(int keyCode){
display.setCurrent(new SecondCanvas(display)); //显示下一个界面
}
}
第二个界面类的代码实现和上一个类似:
Display display;
public SecondCanvas(Display display){
this.display = display;
}
上面的代码演示了如何使用传递Display对象的形式,在界面类中实现切换界面。当然除了该方式以外,需要实现该功能的方式还有很多种,这里只介绍这一种容易理解的实现方式。
2.java程序设计,求详解(最后几个字是:显示用户的选择)
第一步:写思路将全部数据储存到数组中或自定义数据类型或者集合中,因为数据初始化完毕后不会再涉及增删操作所以就用数组了,用户选定座位类型后遍历数组,如果座位可用则返回下标第二步:初始化数据Class xx {private int seats[] = new int[13][6];}//把所有座位都变成可用状态private void init(){for(int i = 0; i < seats.length; i++){for(int j = 0; i < seats[i].length; j++)seats[i][j] = 0; //0=可用}}}第三步:写取座位类型的方法public int getType(){System.out.println("请输入座位类型:1=头等舱,非1=经济舱");Scanner scan = new Scanner(System.in);return scan.nextInt() == 1 ? 1 : 0;}第四步:写分配座位方法public int getSeat(int seatType){for(int i = seatType == 1 ? 0 : 2 ; i < seatType == 1 ? 2 : seats.length; i++){for(int j = 0; i < seats[i].length; j++){if (seats[i][j] = 0)return i*6+j+1;}}}第五步:丢到main方法里public static void main(String[] arg0){System.err.println(getSeat(getType()));}以上代码没有在IDE中检测,直接在百度知道上一个字一个字打的,不保证没错,而且我是JAVA小白- -。
vb显示代码怎么写
1.VB作保存,显示和分别显示的代码怎么写
|'答案e799bee5baa6e78988e69d8331333234333233一
Private Sub Command1_Click()
Dim a As String, b As String
b = Text1.Text + "|" + Text2.Text + "|" + Text3.Text
d = "d:/test.txt"
Open d For Append As #1
Print #1, b
Close #1
End Sub
'答案二
Private Sub Text_Show()
Dim a As String, b As String, c As String
b = "d:/test.txt"
Open b For Input As #1
While Not EOF(1)
Line Input #1, b
List1.AddItem b
Wend
Close #1
End Sub
Private Sub Command2_Click()
Text_Show
End Sub
'答案三
Private Sub List1_Click()
x = InStr(List1.List(List1.ListIndex), "|")
y = InStr(x + 1, List1.List(List1.ListIndex), "|")
Text4 = Left(List1.List(List1.ListIndex), x - 1)
Text5 = Mid(List1.List(List1.ListIndex), x + 1, (y - 1) - (x))
Text6 = Right(List1.List(List1.ListIndex), Len(List1.List(List1.ListIndex)) - y)
End Sub
2.怎么看VB代码、又怎么编写代码
要看VB代码,首先得知道这些代码是什么意思,所以要先学习和了解VB函数及使用及操作方法。
建议先看几本VB编程的书,如:Visual Basic 程序设计 康丽军 吴红萍主编 北京大学出版社 这本书讲的很基础,感觉比较适合初学者。
学习了基本的函数后,就可以对照书中的实例,编写自己的程序了。比如,一个简单的例子。
点击按钮,显示对话框:
1,打开VB,新建程序,然后在窗体中添加一个Command1控件。
2,点击Command1,添加代码:Msgbox "你好!"
3,点击即可。
4,代码编写完毕。
*VB6.0全称为VisualBasic 6.0,是微软公司推出的可视化编程工具之一,是目前世界上使用最广泛的程序开发工具。
3.VB这些代码怎么写
先假定的窗口1名称是form1,窗口2名称是form2。如果不是自己改之
1:点击一个按钮弹出窗口2(弹出后关闭窗口1)
点击后的代码:
Form2.Show '显示窗口2
Unload Me '关闭窗口1
2:点击一个按键后进度条慢慢的满,同时,标签的内容启动切换(一共分10个内容,周期是1秒)。当进度条满时,自动跳到窗口3。
先添加进度条ProgressBar1和定时器Trimer1,标签Label1
代码:
Private Sub Form_Load()
Timer1.Interval = 1000
ProgressBar1.Max = 100
ProgressBar1.Value = 0
End Sub
Private Sub Timer1_Timer()
If ProgressBar1.Value = 100 Then
Form3.Show '显示窗口3
Timer1.Enabled = False
Else
ProgressBar1.Value = ProgressBar1.Value + 1
Select Case (ProgressBar1.Value Mod 10) '显示不同的标签10种
Case 0
Label1.Caption = "0"
Case 1
Label1.Caption = "1"
Case 2
Label1.Caption = "2"
Case 3
Label1.Caption = "3"
Case 4
Label1.Caption = "4"
Case 5
Label1.Caption = "5"
Case 6
Label1.Caption = "6"
Case 7
Label1.Caption = "7"
Case 8
Label1.Caption = "8"
Case 9
Label1.Caption = "9"
End Select
End If
End Sub
3:窗口4上有一个标签,每2秒更换1个内容,共5个内容,当内容更换完后,自动跳到其他的窗口。
这些代码怎么写?悬赏80.
先添加定时器Trimer1,标签Label1,窗口变量T
Dim t As Long
Private Sub Form_Load()
t = 0
Timer1.Interval = 1000
Label1.Caption = "0"
End Sub
Private Sub Timer1_Timer()
t = t + 1
Select Case (t Mod 5)
Case 0
Label1.Caption = "0"
Case 1
Label1.Caption = "1"
Case 2
Label1.Caption = "2"
Case 3
Label1.Caption = "3"
Case 4
Label1.Caption = "4"
Case 5
Timer1.Enabled = False
'其它要显示的窗口
要显示的窗口.show '其它要显示的窗口
unload me '关闭自己
End Select
End Sub
4.vb代码怎么写
首先在Combo1的List属性中加入"a","b","c"
Combo1.click事件中加入代码:
ID = Combo1.List(Combo1.ListIndex())
Select Case ID
Case "a"
Text1.Text = "111"
Case "b"
Text1.Text = "222"
Case "c"
Text1.Text = "333"
Case Else
End Select
转载请注明出处育才学习网 » 显示时间的代码怎么写
育才学习网