编写一个Java Applet小程序---请帮个忙,谢谢

编写一个Java Applet小程序---请帮个忙,谢谢,第1张

import javaapplet;

import javaawt;

import javaawtevent;

public class SmallApplet extends Applet implements ActionListener

{

Label lb1,lb2;

Button btn1,btn2;

TextField tf1;

TextArea ta1;

public void init()

{

lb1=new Label("请在文本框中输入内容!");

lb2=new Label("文本区显示的内容为:");

btn1=new Button("提交");

btn2=new Button("退出");

tf1=new TextField(20);

ta1=new TextArea();

add(lb1);

add(tf1);

add(lb2);

add(ta1);

add(btn1);

add(btn2);

setLayout(new FlowLayout());

setSize(600,400);

setVisible(true);

btn1addActionListener(this);

btn2addActionListener(this);

}

public void actionPerformed(ActionEvent e)

{

if(egetSource()==btn1)

{

ta1setText(tf1getText());

}

if(egetSource()==btn2)

{

Systemexit(0);

}

}

}

import javaawt;

import javaawtevent;

import javaapplet;

public class Try extends Applet implements ActionListener

{

public void init()

{

Button b=new Button("请按按钮");

baddActionListener(this);

add(b);

}

public void actionPerformed(ActionEvent e)

{

Frame f=new Frame("警告");

fsetSize(200,100);

fsetLocation(300,300);

fadd(new Label("你按了按钮!"));

fsetVisible(true);

}

}

请问你是想自定义tabbar的高度还是想调整contentview的高度?你可以使用下面的方法来打印出UITabBarController的View的子视图信息来查看视图层级的布局:-(void)viewDidAppear:(BOOL)animated{[superviewDidAppear:animated];[selfprintViewHierarchy:selftabBarControllerview];}-(void)printViewHierarchy:(UIView)superView{staticuintlevel=0;for(uinti=0;i<level;i++){printf("\t");}constcharclassName=NSStringFromClass([superViewclass])UTF8String;constcharframe=NSStringFromCGRect(superViewframe)UTF8String;printf("%s:%s\n",className,frame);++level;for(UIViewviewinsuperViewsubviews){[selfprintViewHierarchy:view];}--level;}结果如下:UILayoutContainerView:{{0,0},{320,480}}UITransitionView:{{0,0},{320,480}}UIViewControllerWrapperView:{{0,0},{320,480}}UIView:{{0,0},{320,480}}UITabBar:{{0,431},{320,49}}_UITabBarBackgroundView:{{0,0},{320,49}}_UIBackdropView:{{0,0},{320,49}}_UIBackdropEffectView:{{0,0},{320,49}}UIView:{{0,0},{320,49}}UITabBarButton:{{2,1},{156,48}}UITabBarSwappableImageView:{{54,2},{48,32}}UITabBarButtonLabel:{{68,35},{21,12}}UITabBarButton:{{162,1},{156,48}}UITabBarSwappableImageView:{{54,2},{48,32}}UITabBarButtonLabel:{{60,35},{36,12}}UIImageView:{{0,-05},{320,05}}

package tuxingjiemian;

import javaxswing;

import javaxswingevent;

import javaawt;

import javaawtevent;

import javaioFile;

import javaioPrintStream;

public class jishiben extends JFrame {

JPanel jp=new JPanel();

JFrame find_replace=new JFrame();

JMenu file=new JMenu("文件");

JMenu edit=new JMenu("编辑");

JMenu help=new JMenu("帮助");

JMenuBar menubar=new JMenuBar();

JTextArea aa=new JTextArea();

class Open implements ActionListener {

public void actionPerformed(ActionEvent e) {

JFileChooser jf= new JFileChooser();

jfshowOpenDialog(jishibenthis);

try {

PrintStream p=new PrintStream(jfgetSelectedFile()getPath());

} catch (Exception e2) {

}

}

}

class Save implements ActionListener {

public void actionPerformed(ActionEvent e) {

JFileChooser jf= new JFileChooser();

jfshowSaveDialog(jishibenthis);

try {

PrintStream p=new PrintStream(jfgetSelectedFile()getPath());

} catch (Exception e2) {

}

}

}

public jishiben(){

thissetTitle("记事本");

thissetSize(500, 500);

thissetLayout(new BorderLayout());

JMenuItem open=new JMenuItem("打开");

openaddActionListener(new Open());

JMenuItem save=new JMenuItem("保存");

saveaddActionListener(new Save());

JMenuItem exit=new JMenuItem("退出");

exitaddActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

Systemexit(0);

}

});

fileadd(open);

fileadd(save);

fileaddSeparator();

fileadd(exit);

menubaradd(file);

thisadd(new JScrollPane(aa),BorderLayoutCENTER);

JMenuItem copy=new JMenuItem("复制");

JMenuItem past=new JMenuItem("粘贴");

JMenuItem delete=new JMenuItem("删除");

JMenuItem find=new JMenuItem("查找");

JMenuItem replace=new JMenuItem("替换");

copyaddActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

jishibenthisaacopy();

}

});

pastaddActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

jishibenthisaapaste();

}

});

deleteaddActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

jishibenthisaareplaceSelection(null);

}

});

editadd(copy);

editadd(past);

editadd(delete);

editadd(find);

editadd(replace);

menubaradd(edit);

helpadd(new JMenuItem("帮助"));

menubaradd(help);

thisadd(menubar,BorderLayoutNORTH);

thissetVisible(true);

thissetDefaultCloseOperation(thisEXIT_ON_CLOSE);

}

public static void main(String[] args) {

new jishiben();

}

};

lz  你好

具体代码如下:

import javaawt;

import javamath;

import javaxswing;

import javaawtevent;

public class Test extends JFrame{

private JPanel panel;

private JLabel one,equ,result,img,end;

private JTextField input;

private JButton check;

private int first, second;

public Test(){

super("小程序查看器");

one = new JLabel("小程序");

onesetFont(new Font("宋体", FontPLAIN, 15));

makeRandom();

equ = new JLabel(first + "+" + second + "=");

input = new JTextField(10);

check = new JButton("检查");

checkaddActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

int r = IntegerparseInt(inputgetText());

if(first+second == r){

resultsetText("you are right!");

}

else{

resultsetText("you are wrong!");

}

}

});

result = new JLabel();

img = new JLabel(new ImageIcon("1jpg"));

panel = new JPanel(new FlowLayout(FlowLayoutCENTER, 5, 5));

paneladd(equ);

paneladd(input);

paneladd(check);

paneladd(result);

paneladd(img);

end = new JLabel("小程序已启动。");

endsetFont(new Font("宋体", FontPLAIN, 15));

endsetOpaque(true);

endsetBackground(ColorWHITE);

getContentPane()add(one, BorderLayoutNORTH);

getContentPane()add(panel, BorderLayoutCENTER);

getContentPane()add(end, BorderLayoutSOUTH);

setSize(230, 230);

setLocationRelativeTo(null);

setDefaultCloseOperation(3);

setVisible(true);

}

public void makeRandom(){

first = (int)(Mathrandom()  100 + 1);

second = (int)(Mathrandom()  100 + 1);

}

public static void main (String[] args) {

new Test();

}

}

运行结果:

希望能帮助你哈

/计算器/

import javaawt;

import javaxswing;

import javaxswingborder;

import javaawtevent;

public class Calculator implements ActionListener{

JFrame frame;

JPanel panel;

JTextField tfShow;/定义显示文本框/

JButton b1[]=new JButton[10]; /数字按钮/

JButton b2[]=new JButton[6]; / *** 作按钮/

boolean isNumber;/判断是否输入多位数字的变量/

double number;/存储输入数值、显示结果的变量/

double result;/存储中间运算结果的变量/

char operator;/存储当前 *** 作符的成员变量/

public Calculator(){

frame=new JFrame("计算器");

framesetSize(300,300);/指定框架窗口的大小/

framesetResizable(false);/使框架窗口不可改变大小/

JPanel contentPane=(JPanel)framegetContentPane();

contentPanesetBorder(new EmptyBorder(20,20,20,20));/绘制框架的指定大小的空透明边框/

tfShow=new JTextField("0",25);/指定属性的文本域/

tfShowsetHorizontalAlignment(JTextFieldRIGHT);/设置文本域中文本的对齐方式/

isNumber=true;/初始值设置/

number=0;/初始值设置/

result=0;/初始值设置/

operator=' ';/初始值设置/

for(int i=0;i<b1length;i++){

b1[i]=new JButton(IntegertoString(i));/创建数字按钮/

b1[i]setActionCommand(IntegertoString(i));

b1[i]addActionListener(this);

b1[i]setForeground(Colorblue);

}

String bs[]={"/","","-","C","+","="};

for(int i=0;i<b2length;i++){

b2[i]=new JButton(bs[i]);/创建 *** 作按钮/

b2[i]setActionCommand(bs[i]);

b2[i]addActionListener(this);

b2[i]setForeground(Colorred);

}

panel=new JPanel();

panelsetLayout(new GridLayout(4,5));

paneladd(b1[1]);

paneladd(b1[2]);

paneladd(b1[3]);

paneladd(b2[0]);

paneladd(b1[4]);

paneladd(b1[5]);

paneladd(b1[6]);

paneladd(b2[1]);

paneladd(b1[7]);

paneladd(b1[8]);

paneladd(b1[9]);

paneladd(b2[2]);

paneladd(b1[0]);

paneladd(b2[3]);

paneladd(b2[4]);

paneladd(b2[5]);

frameadd(tfShow,BorderLayoutNORTH);/将文本框放置在框架上方/

frameadd(panel,BorderLayoutCENTER);/将装有按钮组的panel放在框架的中心/

framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);/设置框架窗口的默认窗口关闭 *** 作/

framesetVisible(true);/设置框架可见/

}

public double getDisplay(){/返回要显示的结果/

return number;

}

public void reDisplay(){/刷新文本域的内容/

tfShowsetText(""+getDisplay());

}

/对输入数字的处理/

public void numberProcess(int num){

if(isNumber&&num!=0){

String s1=IntegertoString(num);

String s2=IntegertoString((int)(thisnumber));

thisnumber=DoubleparseDouble(s2+s1);/对多位数字的处理/

}else{

thisnumber=num;

}

isNumber=true;/输入连续数字(即多位数字)时为真/

}

public void operationProcess(char operator){/根据输入的 *** 作符改变当前 *** 作符/

switch(operator){

case '-':

thisoperator='-';

break;

case '+':

thisoperator='+';

break;

case '':

thisoperator='';

break;

case '/':

thisoperator='/';

break;

}

result=number;

isNumber=false;/输入 *** 作符时表示输入连续数字的标记变量为假/

}

public void clear(){

number=0;

result=0;

}

public void equal(){/计算运算结果/

switch(operator){

case '-':

result=result-number;

break;

case '+':

result=result+number;

break;

case '':

result=resultnumber;

break;

case '/':

result=result/number;

break;

case ' ':

result=number;

break;

}

number=result; /把运算结果赋值给显示变量/

isNumber=false;

operator=' ';

}

public static void main(String args[]){

Calculator cal=new Calculator();/创建计算器/

}

public void actionPerformed(ActionEvent e){

String command=egetActionCommand();/获取按钮激发的 *** 作事件的命令名称/

char c=commandcharAt(0);/将按钮命令名称的第一个字符赋值给一个字符c/

switch(c){

case '1':

case '2':

case '3':

case '4':

case '5':

case '6':

case '7':

case '8':

case '9':

case '0':

int number=IntegerparseInt(command);

numberProcess(number);/输入数字的处理/

break;

case '+':

case '-':

case '':

case '/':

operationProcess(c);/算数运算符的处理/

break;

case '=':equal();break;/计算运算结果/

case 'C':clear();break;/清零/

}

reDisplay(); /在文本域中显示信息/

}

}

这是我做的一个计算器:运行截图

以上就是关于编写一个Java Applet小程序---请帮个忙,谢谢全部的内容,包括:编写一个Java Applet小程序---请帮个忙,谢谢、编写一个Java的小程序Applet、小程序 tabbar 高度是多少等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9751654.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存