Смекни!
smekni.com

Объектно-ориентированное программирование (стр. 3 из 4)

JPanel panel = new JPanel();

JPanel panel1 = new JPanel();

panel.add(label9);

replace2 = new JButton("OK");

panel1.add(replace2);

contentPane.add(panel,BorderLayout.CENTER);

contentPane.add(panel1,BorderLayout.SOUTH);

}

catch (IOException e)

{

System.out.print("Can not read file66666"+e);

}

replace2.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent event2)

{

System.exit(0);

}

});

}

private JLabel label9;

private JButton replace2;

private String S2;

private String hhh=new String("");

private int r34=0;

private int r3=0;

private DataInputStream ids13;

private Device [] df;

private int [] m1;

private DataInputStream ids131;

private Device [] newStaff1=new Device[10];

static Device[] readData(BufferedReader in)

throws IOException

{

int n = Integer.parseInt(in.readLine());

Device [] e=new Device[n];

for(int i=0;i<n;i++)

{

e[i] = new Device();

e[i].readData(in);

}

return e;

}

}

class ButtonFrame11 extends JFrame

{

public ButtonFrame11()

{

Toolkit kit = Toolkit.getDefaultToolkit();

Dimension screenSize = kit.getScreenSize();

int screenHeight = screenSize.height;

int screenWidth = screenSize.width;

setSize(screenWidth/3,screenHeight/5);

setLocation(screenWidth/4,screenHeight/4);

Image img = kit.getImage("icon.gif");

setIconImage(img);

setTitle("CenteredFrame");

ButtonPanel11 panel = new ButtonPanel11();

add(panel);

}

}

class ButtonPanel11 extends JPanel

{

public ButtonPanel11()

{

JButton BeginButton = new JButton("Begin");

JButton ReButton = new JButton("Registration");

Password = new JPasswordField("",6);

login = new JTextField(15);

label1 = new JLabel("Please,input your name");

label2 = new JLabel("Please,input your password");

JPanel panel = new JPanel();

panel.setLayout(new GridLayout(2,2));

panel.add (label1);

panel.add (login);

panel.add (label2);

panel.add (Password);

add(panel,BorderLayout.CENTER);

JPanel panel1 = new JPanel();

panel1.add(BeginButton);

panel1.add (ReButton);

add(panel1,BorderLayout.SOUTH);

ColorAction11 BeginAction = new ColorAction11(2);

ColorAction11 ReAction = new ColorAction11(3);

BeginButton.addActionListener(BeginAction);

ReButton.addActionListener(ReAction);

}

private class ColorAction11 implements ActionListener

{

public ColorAction11(int c)

{

ccc=c;

t=0;

S1=new String("0");

S2=new String("1");

S3=new String("2");

S4=new String("3");

S5=new String("4");

S6=new String("5");

S7=new String("6");

S8=new String("7");

S9=new String("8");

S10=new String("9");

}

public void actionPerformed(ActionEvent event)

{

if(ccc==2)

{

S13 = login.getText();

pass = Password.getPassword();

S14=new String(pass,0,6);

try

{

FileInputStream is = new

FileInputStream(new

File("C:&bsol;RGR&bsol;"+S13+".txt"));

DataInputStream ids = new DataInputStream(is);

String S15=ids.readUTF();

if (S15.length() == S13.length())

{

if(S13.regionMatches(0, S15, 0, S15.length()))

{

String S16 = ids.readUTF();

if(S13.regionMatches(0, S11, 0, S11.length()))

{

t1=1;

}

if (S14.length() == S16.length())

{

if(S14.regionMatches(0, S16, 0, S16.length()))

{

if(S14.regionMatches(0, r, 0, r.length()))

{

t1=2;

}

FileOutputStream OS=new FileOutputStream (new File("C:&bsol;USER&bsol;NOW.txt"));

DataOutputStream ods = new DataOutputStream (OS);

ods.writeUTF(S13);

ods.close();

GregorianCalendar d = new GregorianCalendar();

int year=d.get(Calendar.YEAR);

int mouth=d.get(Calendar.MONTH);

int day=d.get(Calendar.DAY_OF_MONTH);

int hour=d.get(Calendar.HOUR);

int minute=d.get(Calendar.MINUTE);

int seconds=d.get(Calendar.SECOND);

String S111=""+year;

String S122=""+mouth;

String S133=""+day;

String S144=""+hour;

String S155=""+minute;

String S166=""+seconds;

FileOutputStream OS2=new FileOutputStream (new File("C:&bsol;USER&bsol;Time.txt"));

DataOutputStream ods2 = new DataOutputStream (OS2);

ods2.writeUTF(S111);

ods2.writeUTF(S122);

ods2.writeUTF(S133);

ods2.writeUTF(S144);

ods2.writeUTF(S155);

ods2.writeUTF(S166);

ods2.close();

if(t1==2)

{

FileOutputStream OS6=new FileOutputStream (new File("C:&bsol;USER&bsol;teacher.txt"));

DataOutputStream ods6 = new DataOutputStream (OS6);

ods6.writeUTF("1");

ods6.close();

}

else

{

FileOutputStream OS6=new FileOutputStream (new File("C:&bsol;USER&bsol;teacher.txt"));

DataOutputStream ods6 = new DataOutputStream (OS6);

ods6.writeUTF("0");

ods6.close();

}

ButtonFrame frame = new ButtonFrame ();

frame.setVisible(true);

}

}

}

}

else

{

System.out.print("You full!");

}

}

catch (IOException e)

{

System.out.print("Can not read file77777"+e);

}

}

if(ccc==3)

{

try{

t++;

S13 = login.getText();

System.out.println(S13);

pass = Password.getPassword();

System.out.println(pass);

S14=new String(pass,0,6);

File file = new File("C:&bsol;RGR&bsol;"+S13+".txt");

File file1 = new File("C:&bsol;KURS&bsol;"+S13+".txt");

File file2 = new File("C:&bsol;Student&bsol;"+S13+".txt");

File file3 = new File("C:&bsol;Student1&bsol;"+S13+".txt");

try

{

file.createNewFile();

file1.createNewFile();

file2.createNewFile();

file3.createNewFile();

}

catch(IOException e)

{

System.out.println("Can not create new file"+e);

}

FileOutputStream OS=new FileOutputStream (new File("C:&bsol;RGR&bsol;"+S13+".txt"));

DataOutputStream ods = new DataOutputStream (OS);

ods.writeUTF(S13);

ods.writeUTF(S14);

ods.close();

FileOutputStream OS1=new FileOutputStream (new File("C:&bsol;KURS&bsol;"+S13+".txt"));

DataOutputStream ods1 = new DataOutputStream (OS1);

ods1.writeUTF(S1);

ods1.writeUTF(S2);

ods1.writeUTF(S3);

ods1.writeUTF(S4);

ods1.writeUTF(S5);

ods1.writeUTF(S6);

ods1.writeUTF(S7);

ods1.writeUTF(S8);

ods1.writeUTF(S9);

ods1.writeUTF(S10);

ods1.close();

}

catch(IOException e)

{

System.out.println("Can not write file"+e);

}

}

}

private int ccc;

private char[] pass = new char[20];

private String S13;

private String S14;

private boolean dd;

private int t;

private int t1=0;

private String r="111111";

private String S1;

private String S2;

private String S3;

private String S4;

private String S5;

private String S6;

private String S7;

private String S8;

private String S9;

private String S10;

private String S11="lector";

}

private JPasswordField Password;

private JTextField login;

private JLabel label1;

private JLabel label2;

}

class CheckBoxFrame extends JFrame

{

public CheckBoxFrame()

{

setTitle("Test");

setSize(600,200);

Container contentPane = getContentPane ();

JPanel panel = new JPanel ();

label = new JLabel ("Внимания, вы проходите тестирование - не дурачится и внимательно вчитывайтесь в вопрос!");

contentPane.add(label,BorderLayout.NORTH);

replace1=new JButton("Finish");

replace = new JButton("Next");

panel.add(replace);

panel.add(replace1);

contentPane.add(panel,BorderLayout.SOUTH);

try

{

FileInputStream is45 = new

FileInputStream(new

File("C:&bsol;USER&bsol;NOW.txt"));

DataInputStream ids45 = new DataInputStream(is45);

S2=ids45.readUTF();

FileInputStream is = new

FileInputStream(new

File("C:&bsol;USER&bsol;Control.txt"));

ids = new DataInputStream(is);

}

catch(IOException e)

{

System.out.print("Can not read file888888"+e);

}

replace1.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent event2)

{

label.setText("Ваш результат - "+fff*10+"% угаданых вопросов от общего количества вопросов");

}

});

replace.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent event2)

{

w=0;

c=0;

try

{

if(y<10)

{

S3=ids.readUTF();

label.setText("<html>Внимания, вы проходите тестирование - не дурачится и внимательно вчитывайтесь в вопрос!<br>"+S3);

}

}

catch(IOException e)

{

System.out.print("Can not read file5555"+e);

}

}

});

buttonPanel = new JPanel();

group = new ButtonGroup ();

addRadioButton("Дa",3);

addRadioButton("Частично",1);

addRadioButton("Нет",2);

addRadioButton("Другойответ",0);

contentPane.add(buttonPanel,BorderLayout.CENTER);

try

{

FileInputStream is4 = new

FileInputStream(new

File("C:&bsol;USER&bsol;Answers.txt"));

ids4 = new DataInputStream(is4);

}

catch(IOException e)

{

System.out.print("Can not read file4444"+e);

}

}

public void addRadioButton(String name, final int size)

{

boolean selected = size==mode;

JRadioButton button = new JRadioButton(name,selected);

group.add(button);

buttonPanel.add(button);

try{

OS=new FileOutputStream (new File("C:&bsol;Student1&bsol;"+S2+".txt"));

ods = new DataOutputStream (OS);

}

catch (IOException e)

{

System.out.print("Can not read file3333"+e);

}

ActionListener listerner = new ActionListener()

{

public void actionPerformed(ActionEvent event1)

{

if(c==0)

{

if(y<10)

{

w++;

if(w==1)

{

try

{

String S31=ids4.readUTF();

r=Integer.parseInt(S31);

}

catch(IOException e)

{

System.out.print("Can not read file2222"+e);

}

if(r==size)

{

fff++;

try{

String X=""+y;

ods.writeUTF(X);

OS1=new FileOutputStream (new File("C:&bsol;Student&bsol;"+S2+".txt"));

ods1 = new DataOutputStream (OS1);

S3=""+fff;

ods1.writeUTF(S3);

}

catch (IOException e)

{

System.out.print("Can not read file111"+e);

}

}

}

}

}

y++;

}

};

button.addActionListener(listerner);

}

private JLabel label;

private JPanel buttonPanel;

private ButtonGroup group;

private static final int mode=0;

private int fff=0;

private int r=0;

private JButton replace;

private JButton replace1;

private int y=0;

private int c=1;

private String S3;

private String S2;

private DataInputStream ids4 ;

private DataInputStream ids;

private FileOutputStream OS;

private DataOutputStream ods;

private FileOutputStream OS1;

private DataOutputStream ods1;

private int w=0;

}

class JFrame1 extends JFrame

{

public JFrame1()

{

setSize(400,300);

ButtonPanel1 panel = new ButtonPanel1();

add(panel);

}

}

class ButtonPanel2 extends JPanel

{

public ButtonPanel2()

{

S133 =JOptionPane.showInputDialog("Введителогинискомогостудента");

JButton Change = new JButton("Change");

m_1=new JTextField(5);

m_2=new JTextField(5);

m_3=new JTextField(5);

m_4=new JTextField(5);

m_5=new JTextField(5);

m_6=new JTextField(5);

m_7=new JTextField(5);

m_8=new JTextField(5);

m_9=new JTextField(5);

m_10=new JTextField(5);

JLabel l = new JLabel("Please, give me a logical speach, if you already want to change:");

JLabel l1 = new JLabel("Массив в С++: его значение, применение, свойства:");

JLabel l2 = new JLabel("Размер передаваемого массива");

JLabel l3 = new JLabel("Передача массивов как указателей");

JLabel l4 = new JLabel("Преимущества передачи массива как указателя");

JLabel l5 = new JLabel("Проблемы связаны с передачой массива...");

JLabel l6 = new JLabel("Некоторые особенности поведения компилятора");

JLabel l7 = new JLabel("Примеры правильного кода");

JLabel l8 = new JLabel("Массив обявленный как ссылка");

JLabel l9 = new JLabel("Использование абстрактного контейнера - это плохо?");

JLabel l10 = new JLabel("Коечто о шаблонах их работе и многом другом");

JPanel panel1 = new JPanel();

panel1.setLayout(new GridLayout(10,2));

add (l,BorderLayout.NORTH);

panel1.add (l1);

panel1.add (m_1);

panel1.add (l2);

panel1.add (m_2);

panel1.add (l3);

panel1.add (m_3);

panel1.add (l4);

panel1.add (m_4);

panel1.add (l5);

panel1.add (m_5);

panel1. add (l6);

panel1.add (m_6);

panel1.add (l7);

panel1.add (m_7);

panel1.add (l8);

panel1.add (m_8);

panel1.add (l9);

panel1.add (m_9);

panel1.add (l10);

panel1. add (m_10);

add(panel1,BorderLayout.CENTER);

add (Change,BorderLayout.SOUTH);

Change.addActionListener( new ActionListener(){public void actionPerformed(ActionEvent event)

{

try{

S2 = m_1.getText();

S3 = m_2.getText();

S4 = m_3.getText();

S5 = m_4.getText();

S6 = m_5.getText();

S7 = m_6.getText();

S8 = m_7.getText();

S9 = m_8.getText();

S10 = m_9.getText();

S11 = m_10.getText();

FileOutputStream OS=new FileOutputStream (new File("C:&bsol;KURS&bsol;"+S133+".txt"));

DataOutputStream ods = new DataOutputStream (OS);

ods.writeUTF(S2);

ods.writeUTF(S3);

ods.writeUTF(S4);

ods.writeUTF(S5);

ods.writeUTF(S6);

ods.writeUTF(S7);

ods.writeUTF(S8);

ods.writeUTF(S9);

ods.writeUTF(S10);

ods.writeUTF(S11);

ods.close();

}

catch(IOException e)

{

System.out.print("Can not read file99999"+e);

}

}

});

}

public ButtonPanel2(int e)

{

w=e;

m1[0]=0;

m1[1]=1;

m1[2]=2;

m1[3]=3;

m1[4]=4;

m1[5]=5;

m1[6]=6;

m1[7]=7;

m1[8]=8;

m1[9]=9;

}

private JTextField m_1;

private JTextField m_2;

private JTextField m_3;

private JTextField m_4;

private JTextField m_5;

private JTextField m_6;

private JTextField m_7;

private JTextField m_8;

private JTextField m_9;

private JTextField m_10;

private String S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S133;

protected int [] m1=new int[10];

int w=0;

public int[] getPrivios ()

{

return m1;

}

}

class JFrame2 extends JFrame

{

public JFrame2()

{

setSize(650,325);

ButtonPanel2 panel1 = new ButtonPanel2();

add(panel1);

}

}

class ButtonPanel1 extends JPanel

{

public ButtonPanel1()

{

JButton NextButton = new JButton("Next");

textArea = new JTextArea(12,35);

textArea.setEditable(false);

textArea.setLineWrap(true);