1.设计一窗口,内含一个按钮。开始运行时,按钮显示“Click Me”字样,当按钮按下时,按钮上的文字变成“Click Me Again”,再按一次,则变成原来的“Click Me”字样,依次循环
2.编写一个程序,从一个文本文件中读取数据,一次读取一行文本
3.编写一个Applet,点击“start”按钮,改变窗口颜色,同时“start”变为“stop”。
1.设计一窗口,内含一个按钮。开始运行时,按钮显示“Click Me”字样,当按钮按下时,按钮上的文字变成“Click Me Again”,再按一次,则变成原来的“Click Me”字样,依次循环
2.编写一个程序,从一个文本文件中读取数据,一次读取一行文本
3.编写一个Applet,点击“start”按钮,改变窗口颜色,同时“start”变为“stop”。
确定是用Java?设计窗体还是c#比较好吧?
public class static void main(String args[]){
String one="Click Me",two="Click Me Again";
boolean yn=true;
int i=0;
do{i--;
if(yn){
System.out.print(one);
yn!=yn;
}else{
System.out.print(two);
yn!=yn;
}
}while(i=6);
}
第三题:
import javax.swing.JButton; import java.awt.Color; import java.awt.Container; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JApplet; import javax.swing.JPanel;
public class Test extends JApplet { public void init() { Container con = getContentPane(); con.add(new Buttonpanel()); }
}
class Buttonpanel extends JPanel { private String a="start",b="stop"; JButton button ; public Buttonpanel() { button =new JButton(a); button.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub if(button.getText().equals("start")) { setBackground(Color.pink); button.setText(b); }else { setBackground(Color.red); button.setText(a); } }
public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub }
public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub }
public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub }
public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } }); add(button); } }
编译后在当前目录下建一个文本内容:
<applet code="Test.class" width=1000 height=900> </applet>
第一题:
import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent;
import javax.swing.JButton; import javax.swing.JFrame;
public class FrameTest extends MouseAdapter { private JFrame frame; private Container c; private JButton jb; public FrameTest(){ frame = new JFrame(); frame.setBounds(200, 300, 200, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); c = frame.getContentPane(); jb =new JButton("Click Me!"); jb.addMouseListener(this); c.add(jb,BorderLayout.NORTH); }
public void go(){ frame.setVisible(true); } @Override public void mouseClicked(MouseEvent e) { if(jb.getText().equals("Click Me!")){ jb.setText("Click Me Again"); }else{ jb.setText("Click Me!"); } }
public static void main(String[] args) { FrameTest ft = new FrameTest(); ft.go(); } }