}
}
class ChoiceLike extends Frame {
public static void main(String args[]) {
MyPanel1 panel1 = new MyPanel1(); MyPanel2 panel2 = new MyPanel2(); MyPanel3 panel3 = new MyPanel3(); ChoiceLike mainFrame = new ChoiceLike();
mainFrame.add(panel1,BorderLayout.WEST); mainFrame.add(panel2,BorderLayout.CENTER); mainFrame.add(panel3,BorderLayout.EAST); mainFrame.setVisible(true); } }
1、设计一个图形用户界面的颜色合成程序,界面如下图所示。要求改变任一颜色值时,合成颜色实时变化。
import java.awt.*; import java.awt.event.*;
public class RGBColor extends WindowAdapter implements TextListener {
服装制版视频淘宝才智在线
Frame f;
TextField tf1,tf2,tf3; Panel p2; public RGBColor() {
f=new Frame(\合成颜色\f.setSize(500,200); Panel p1=new Panel(); p2=new Panel(); f.add(p1,\f.add(p2);
p1.add(new Label(\tf1=new TextField(\p1.add(tf1);
p1.add(new Label(\tf2=new TextField(\p1.add(tf2);
p1.add(new Label(\tf3=new TextField(\p1.add(tf3);
tf1.addTextListener(this); tf2.addTextListener(this); tf3.addTextListener(this);
p2.setBackground(new Color(255,0,0));
服装制版视频淘宝才智在线
}
}
f.setVisible(true);
f.addWindowListener(this);
public void textValueChanged(TextEvent e) { }
public void windowClosing(WindowEvent e) { }
public static void main(String k[]) { }
new RGBColor(); System.exit(0);
int r=(new Integer(tf1.getText())).intValue(); int g=(new Integer(tf2.getText())).intValue(); int b=(new Integer(tf3.getText())).intValue();
p2.setBackground(new Color(r,g,b));
2、设计一个密码验证程序,如下图所示。要求:当输入正确的密码“123456”时,验证文本域显示“you pass!”,否则显示密码错误的信息“your password error!”。
服装制版视频淘宝才智在线
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class Login1 { }
class LoginFrame extends JFrame {
public LoginFrame() {
setTitle(\
setSize(WIDTH, HEIGHT);
Container contentPane = getContentPane(); //建立容器面板
JPanel textPanel = new JPanel(); //新建输入密码标签
JLabel inputPassword = new JLabel(\myPassword = new JPasswordField(20); public static void main(String[] args) { }
LoginFrame frame = new LoginFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show();
服装制版视频淘宝才智在线
}
textPanel.add(inputPassword); textPanel.add(myPassword); //新建密码验证标签
JLabel checkedPassword = new JLabel(\checkPassword = new JTextField(20); checkPassword.setEditable(false); textPanel.add(checkedPassword); textPanel.add(checkPassword);
loginButton = new JButton(\登录\//注册事件监听器
loginButton.addActionListener(new LoginAction()); textPanel.add(loginButton); contentPane.add(textPanel);
//实现事件监听器 private class LoginAction {
public void actionPerformed(ActionEvent event) {
//获取密码域的内容
char[] s = myPassword.getPassword(); String gets = new String(s);
if(gets.equals(CHECKPASSWORD)) { } else {
checkPassword.setText(\checkPassword.setText(\
implements ActionListener
服装制版视频淘宝才智在线
《面向对象程序设计(Java)》机试题库(含答案)



