<html>
<script type="text/javascript">
function change(){
var color = documentgetElementById("color")value;
var div = documentgetElementById("text");
if (color)
divstylecolor = color;
}
</script>
<body>
<div id="text">今天你学JAVA了吗</div>
<input type="textfield" id="color" />
<input type="button" onclick="change();" value="确定"/>
</body>
</html>
class Ball {
public void play() {
Systemoutprintln("玩球儿");
}
}
class Football extends Ball {
public void play() {
Systemoutprintln("使用足球运动");
}
}
class Basketball extends Ball {
public void play() {
Systemoutprintln("使用篮球运动");
}
}
public class TestMain {
public static void main(String[] args) {
TestMain tm = new TestMain();
tmtestPlay();
}
public void testPlay() {
Ball ball = new Football();
ballplay();
ball = new Basketball();
ballplay();
}
}
/
D:\>javac TestMainjava
D:\>java TestMain
使用足球运动
使用篮球运动
/
import javaawtColor;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJPanel;
public class Screen{
public static void main(String args[]){
new Win();
}
static class Win extends JFrame implements ActionListener{
JPanel jp = new JPanel();
JButton jb[] = new JButton[4];
public Win(){
thissetBounds(0, 0, 320, 320);
Color c[] = {Colorred,Coloryellow,Colorblue};
jpsetBackground(Colorblack);
for(int i = 0 ; i < 4 ; i++){
jb[i] = new JButton();
if(i!=3){
jb[i]setBackground(c[i]);
}else{
jb[i]setText("退出");
}
jb[i]addActionListener(this);
jpadd(jb[i]);
}
thisadd(jp);
thissetVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(!((JButton)egetSource())getText()equals("退出")){//如果不是退出按钮,则换颜色
jpsetBackground(((JButton)egetSource())getBackground());
}
else
Systemexit(0);//退出
}
}
}
以上就是关于一个用JAVA做网页的小程序全部的内容,包括:一个用JAVA做网页的小程序、java一个简单小程序,求高手帮忙编写,万分感谢、Java~有哪位大虾可以帮我写一个小程序呀,用Java做一个界面,上面有四个按钮分别是红色,黄色,蓝色,退出,等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)