📄 chap.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.Box;
import java.applet.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class chap extends JApplet implements ActionListener
{
String userName;
String userPass;
ObjectOutputStream oos;
ObjectInputStream ois;
JLabel lUser;
JTextField tfName;
JLabel lPass;
JPasswordField pfPass;
JButton btLogin;
JButton btReset;
JPanel mPanel;
TextArea textinput;
TextArea textoutput;
JButton buttonsend;
JButton buttonexits;
JButton buttonFont;
JButton buttonpictrue;
JPanel panel;
int paintStage=0;
mydialog dialog1;
mydialog2 dialog2;
Button buttonEnter;
Button buttonexit;
JButton pictrue;
Icon ig;
Choice choice1;
Choice choice2;
Choice choice3;
public void init()
{
paintStage=0;
//以下为建立第一登录界面
mPanel = (JPanel)this.getContentPane();
mPanel.setLayout(null);
lUser = new JLabel("用户:");
lUser.setBounds(10, 10, 50, 20);
tfName = new JTextField(10);
tfName.setBounds(70, 10, 160, 20);
lPass = new JLabel("密码:");
lPass.setBounds(10, 40, 50, 20);
pfPass = new JPasswordField(10);
pfPass.setBounds(70, 40, 160, 20);
btLogin = new JButton("Login");
btLogin.setBounds(40, 90, 80, 20);
btLogin.addActionListener(this);
btReset = new JButton("Reset");
btReset.setBounds(130, 90, 80, 20);
btReset.addActionListener(this);
mPanel.add(lUser);
mPanel.add(tfName);
mPanel.add(lPass);
mPanel.add(pfPass);
mPanel.add(btLogin);
mPanel.add(btReset);
}
public void actionPerformed(ActionEvent e)
{
//处理对登录界面按钮的点击
if (e.getSource() == btLogin)
{Chap ();
/* try
{
Socket cs = new Socket("127.0.0.1", 10000);
oos = new ObjectOutputStream(cs.getOutputStream());
ois = new ObjectInputStream(cs.getInputStream());
//向服务器验证用户身份
Message u = new Message();
u.m1 = tfName.getText();
u.m2 = String.valueOf(pfPass.getPassword());
oos.writeObject(u);
Message tu = (Message)ois.readObject();
if (tu.m1.equalsIgnoreCase(new String("OK")))
{
//若为合法用户,则出现界面
//}
//else
// {
// JOptionPane.showMessageDialog(null,"input right number","Messenge",JOptionPane.ERROR_MESSAGE);
// }
}
catch(Exception e1)
{
e1.printStackTrace();
}*/
}
else
{
tfName.setText("");
pfPass.setText("");
}
}
public void Chap()
{ paintStage=1;
mPanel.removeAll();
this.setSize(400,420);
panel=new JPanel();
panel = (JPanel)this.getContentPane();
panel.setLayout(null);
textinput = new TextArea("",10,10,textoutput.SCROLLBARS_BOTH);
textinput.setBounds(20,240,355,120);
textoutput = new TextArea("",10,10,textoutput.SCROLLBARS_BOTH);
textoutput.setBounds(20,20,355,165);
Myframe myframe = new Myframe();
buttonpictrue= new JButton("图片");
buttonpictrue.setBounds(60,200,60,30);
buttonpictrue.addActionListener(myframe);
buttonFont=new JButton("字体");
buttonFont.setBounds(150,200,60,30);
buttonFont.addActionListener(myframe);
buttonsend= new JButton("发送");
buttonsend.setBounds(60,380,60,30);
buttonsend.addActionListener(myframe);
buttonexits=new JButton("退出");
buttonexits.setBounds(150,380,60,30);
buttonexits.addActionListener(myframe);
panel.add(buttonFont);
panel.add(buttonpictrue);
panel.add(textinput);
panel.add(textoutput);
panel.add(buttonsend);
panel.add(buttonexits);
}
class Myframe extends JFrame implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
ObjectOutputStream oos;
ObjectInputStream ois;
if(e.getSource()==buttonsend)
{
textoutput.append("\n"+textinput.getText());
textinput.setText("");
}
else if(e.getSource()==buttonexits)
{
this.dispose();
}
else if(e.getSource()==buttonFont)
{
dialog1=new mydialog(this);
}
else if(e.getSource()==buttonpictrue)
{
dialog2=new mydialog2(this);
}
else
{System.out.println("jkjkklklk");
}
}
}
class mydialog extends Dialog implements ItemListener,ActionListener
{
public mydialog(Frame parent)
{
super(parent,"字体",true);
setLayout(new FlowLayout());
add(new Label("字体大小:"));
choice1=new Choice();
choice1.addItem("10");
choice1.addItem("12");
choice1.addItem("14");
choice1.addItem("18");
this.add(choice1);
choice1.addItemListener(this);
add(new Label(" 字形类型:"));
choice2=new Choice();
choice2.addItem("粗体");
choice2.addItem("普通");
choice2.addItem("斜体");
this.add(choice2);
add(new Label("字体名:"));
choice3=new Choice();
choice3.add("Dialog");
choice3.add("DialogInput");
choice3.add("SansSerif");
choice3.add("Serif");
choice3.add("Monospaced");
this.add(choice3);
add(buttonEnter=new Button("确定"));
buttonEnter.addActionListener(this);
add(buttonexit=new Button("退出"));
buttonexit.addActionListener(this);
setSize(600,100);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{ if(ae.getSource()==buttonexit)
{
dispose();
}
if(ae.getSource()==buttonEnter)
{
choice1.getSelectedItem();
choice2.getSelectedItem();
choice3.getSelectedItem();
dispose();
}
}
public void itemStateChanged(ItemEvent e)
{
if(choice1.getSelectedIndex()==0&&choice2.getSelectedIndex()==0)
{
if(choice3.getSelectedIndex()==0)
{
textinput.setFont(new Font("Dialog",Font.BOLD,10));
}
if(choice3.getSelectedIndex()==1)
{
textinput.setFont(new Font("DialogInput",Font.BOLD,10));
}
if(choice3.getSelectedIndex()==2)
{
textinput.setFont(new Font("SansSerif",Font.BOLD,10));
}
if(choice3.getSelectedIndex()==3)
{
textinput.setFont(new Font("Serif",Font.BOLD,10));
}
if(choice3.getSelectedIndex()==4)
{
textinput.setFont(new Font("Monospaced",Font.BOLD,10));
}
}
if(choice1.getSelectedIndex()==0&&choice2.getSelectedIndex()==1)
{
if(choice3.getSelectedIndex()==0)
{
textinput.setFont(new Font("Dialog",Font.PLAIN,10));
}
if(choice3.getSelectedIndex()==1)
{
textinput.setFont(new Font("DialogInput",Font.PLAIN,10));
}
if(choice3.getSelectedIndex()==2)
{
textinput.setFont(new Font("SansSerif",Font.PLAIN,10));
}
if(choice3.getSelectedIndex()==3)
{
textinput.setFont(new Font("Serif",Font.PLAIN,10));
}
if(choice3.getSelectedIndex()==4)
{
textinput.setFont(new Font("Monospaced",Font.PLAIN,10));
}
}
if(choice1.getSelectedIndex()==0&&choice2.getSelectedIndex()==2)
{
if(choice3.getSelectedIndex()==0)
{
textinput.setFont(new Font("Dialog",Font.ITALIC,10));
}
if(choice3.getSelectedIndex()==1)
{
textinput.setFont(new Font("DialogInput",Font.ITALIC,10));
}
if(choice3.getSelectedIndex()==2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -