编写一个简单的Java Applet程序,显示两行文字“这是一个Java Applet程序”和“欢迎学习Java”

编写一个简单的Java Applet程序,显示两行文字“这是一个Java Applet程序”和“欢迎学习Java”,第1张

import javaappletApplet;

import javaawtColor;

import javaawtFont;

import javaawtGraphics;

public class DrawString extends Applet {

public void paint(Graphics g)

{

gsetFont(new Font("宋体",FontBOLD,36));

gsetColor(Colorgreen);

gdrawString("这是一个Java Applet程序",5,30);

gsetColor(Colorred);

gdrawString("欢迎学习Java",5,80);

}

}

你的算法有问题,我再你得基础上修改下:

import javaappletApplet;

import javaawtEvent;

import javaawtLabel;

import javaawtTextField;

public class HUiWen extends Applet {

Label prompt;

TextField input;

int data;

public void init() {

prompt = new Label("输入数字");

input = new TextField(4);

add(prompt);

add(input);

}

public boolean action(Event e, Object o) {

int data = IntegerparseInt(inputgetText());

showStatus("");

inputsetText("");

int count = 0;

String[] arr = new String[1000000];

while (data != 0) {

arr[count] = StringvalueOf(data % 10);

data = data / 10;

count++;

}

int j = count - 1;

boolean flag = true;

for (int i = 0; i < count / 2; i++, j--) {

if (!arr[i]equals(arr[j])){

showStatus("不是回文数");

flag = false;

}

}

if(flag){

showStatus("是回文数");

}

repaint();

return true;

}

}

我自己写的处理回文,比你那个省内存

import javaappletApplet;

import javaawtEvent;

import javaawtLabel;

import javaawtTextField;

public class HUiWen extends Applet {

Label prompt;

TextField input;

public void init() {

prompt = new Label("输入数字");

input = new TextField(4);

add(prompt);

add(input);

}

public boolean action(Event e, Object o) {

String text = inputgetText()trim();

showStatus("");

inputsetText("");

StringBuilder sb = new StringBuilder(text);

if (sbreverse()toString()equals(text)) {

showStatus("不是回文数");

} else {

showStatus("是回文数");

}

repaint();

return true;

}

}

import javaawt;

import javaapplet;

//<applet code=Char height=200 width=200></applet>

public class Char extends Applet

{

Panel p=new Panel();

Label l1=new Label("abcdefghij");

Label l2=new Label("klmnopqrst");

Label l3=new Label("uvwxyz");

public void init()

{

psetLayout(new GridBagLayout());

GridBagConstraints gbc = new GridBagConstraints();

gbcanchor = GridBagConstraintsWEST; //设定Layout的位置

gbcinsets = new Insets(2,2,2,2); //设定与边界的距离(上,左,下,右)

gbcgridy=1;

gbcgridx=0;

padd(l1,gbc);

gbcgridy=2;

gbcgridx=0;

padd(l2,gbc);

gbcgridy=3;

gbcgridx=0;

padd(l3,gbc);

add(p);

}

}

import javaappletApplet;

import javaawtButton;

import javaawtGraphics;

import javaawtTextField;

import javaawteventActionEvent;

import javaawteventActionListener;

import javaawteventKeyEvent;

import javaawteventKeyListener;

public class Numberpow extends Applet implements KeyListener

{

private TextField tf1,tf2;

private Button b;

public void init() {

// TODO Auto-generated method stub

tf1=new TextField(8);

tf2=new TextField(8);

tf2setEditable(false);

thisaddKeyListener(this);

tf1addKeyListener( this);

thisadd( tf1);

thisadd( tf2);

}

public void paint(Graphics g) {

// TODO Auto-generated method stub

gdrawString("按下空格键清空",20,100);

}

public void keyTyped(KeyEvent e) {

// TODO Auto-generated method stub

char ch=egetKeyChar();

if(ch==' ')

{

tf1setText( "");

tf2setText( "");

esetKeyChar('\n');

}

else if(ch>'9' || ch<'0')

{

esetKeyChar('\n');

}

else

{

String s=tf1getText()+ch ;

if(!sequals(""))

{

int i=IntegerparseInt( s);

i=(int)Mathpow( (double)i,20);

tf2setText( new Integer(i)toString() );

}

}

}

public void keyPressed(KeyEvent e) {

// TODO Auto-generated method stub

}

public void keyReleased(KeyEvent e) {

// TODO Auto-generated method stub

}

}

import javaapplet;

import javaawt;

import javaawteventActionEvent;

import javaawteventActionListener;

public class test extends Applet implements ActionListener

{

Label lb1,lb2;

TextField tf;

Button btn;

public void init()

{

lb1 = new Label("请输入一个整数:");

lb2 = new Label(" ");

tf = new TextField(10);

btn = new Button("判断");

setLayout(new FlowLayout());

add(lb1);

add(tf);

add(btn);

add(lb2);

btnaddActionListener(this);

setSize(200,200);

setVisible(true);

}

public void actionPerformed(ActionEvent e)

{

if(egetSource()==btn)

{

StringBuffer source = new StringBuffer(tfgetText());

sourcereverse();

String reverseString = new String(source);

if(reverseStringequals(tfgetText()))

lb2setText(tfgetText()+"是回文!");

else

lb2setText(tfgetText()+"不是回文!");

}

}

}

public void paint(Graphics g){

superpaint(g);

if(left == 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);

}

}

}

以上就是关于编写一个简单的Java Applet程序,显示两行文字“这是一个Java Applet程序”和“欢迎学习Java”全部的内容,包括:编写一个简单的Java Applet程序,显示两行文字“这是一个Java Applet程序”和“欢迎学习Java”、我在java中编写applet的程序,希望能判断输入的数是否是回文数,但是最后判断总是出错,麻烦大家看看,急、编写Applet程序,在屏幕上输出A到Z的26个字母,排成三行,前两行每生10个字母,最后一行6个字母。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存