Часовой пояс: UTC + 3 часа




Начать новую тему Новая тема / Ответить на тему Ответить  Сообщений: 3 
  Версия для печати (полностью) Пред. тема | След. тема 
В случае проблем с отображением форума, отключите блокировщик рекламы
Автор Сообщение
 

Member
Статус: Не в сети
Регистрация: 01.08.2005
Откуда: Msk
Доброго времени суток, форумчане! Всех с наступившим новым годом!
Помогите разобраться с прогой. Нужны комментарии к строкам программы (Какая что делает и за что отвечает)


Листинг программы:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.FileNotFoundException;
import javax.swing.*;
public class Aplic extends JFrame
{ private JComboBox comm_choice;
private Lab1 myLab;
private JTextField txtToFile_Field,NameOfFile;
private JLabel txtOfFile,txtToFile_C;
private JButton button;
public Aplic()
{
super("Приложение");
createGUI();
}
public void createGUI()
{
JLabel txt,txtOfFile_C,comm,NameOfFile_C;

myLab = new Lab1();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel();panel.setLayout(null);
NameOfFile_C= new JLabel("Введите путь к файлу");NameOfFile_C.setBounds(0, 5, 160, 14);
NameOfFile = new JTextField();
NameOfFile.setBounds(140, 5, 160, 20);
NameOfFile.setText("C:\\1.txt");
comm = new JLabel("Выберите команду");comm .setBounds(0, 30, 120, 14);
comm_choice = new JComboBox();
comm_choice .setBounds(140, 30, 160, 20);comm_choice.addItem(" ");
comm_choice.addItem("Записать");
comm_choice.addItem("Чтение");
comm_choice.addItem("Разобрать");
button = new JButton("Выполнить");
button .setBounds(200, 80, 100, 20);txtToFile_C = new JLabel("Введите строку:");txtToFile_C.setBounds(0, 55, 160, 14); txtToFile_Field = new JTextField(20); txtToFile_Field.setBounds(140, 55, 160, 20);txtOfFile_C = new JLabel("Содержание файла");txtOfFile_C .setBounds(99, 110, 160, 14); txtOfFile = new JLabel(""); txtOfFile.setBounds(99, 130, 160, 14); txtToFile_C.setVisible(false);
txtToFile_Field.setVisible(false);
panel.add(NameOfFile_C);
panel.add(NameOfFile);
panel.add(comm);
panel.add(comm_choice);
panel.add(txtToFile_C);
panel.add(txtToFile_Field);
panel.add(button);
panel.add(txtOfFile_C);
panel.add(txtOfFile);
ActionListener actionListener = new ActListener();
button.addActionListener(actionListener) comm_choice.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent arg0){
if (comm_choice.getSelectedIndex()==1)
{txtToFile_C.setVisible(true);
txtToFile_Field.setVisible(true);
} else {txtToFile_C.setVisible(false);
txtToFile_Field.setVisible(false);
}}});getContentPane().add(panel);
panel.setPreferredSize(new Dimension(350, 198));
}/*createGUI()*/
public class ActListener implements ActionListener{public void actionPerformed(ActionEvent ae){
If {comm_choice.getSelectedIndex()==1)
{try {myLab.writeTextToFile(NameOfFile.getText(), txtToFile_Field.getText());
} catch (FileNotFoundException e)
{// TODO Auto-generated catch block
e.printStackTrace();}} else if (comm_choice.getSelectedIndex()==2){
try {txtOfFile.setText(myLab.ReadTextToFile(NameOfFile.getText(), txtToFile_Field.getText()));
} catch (FileNotFoundException e)
{// TODO Auto-generated catch block
e.printStackTrace();}}
else if (comm_choice.getSelectedIndex()==3)
{try {txtOfFile.setText(myLab.Collection(NameOfFile.getText()));} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();}}}/*actionPerformed*/
}/*ActListener*/ public static void main (String[] args){javax.swing.SwingUtilities.invokeLater
new Runnable() {public void run()
JFrame.setDefaultLookAndFeelDecorated(true); Aplic frame = new Aplic();
Frame.pack(); frame.setLocationRelativeTo(null);
frame.setVisible(true);}});}/*main*/}


import java.io.*;
import java.util.*;
public class Lab1
{
public String textToApplet;
/**
* @throws IOException
* @param args
* @throws
*/
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
}

float stepen(float x,int n)
{
float spn = 0; float r=1;
for (int i=1;i <= n;i++ )
{
r=r*x;
spn=r;
}
return (spn);
}

void writeTextToFile(String filename, String text) throws FileNotFoundException
{

try {
BufferedWriter out = new BufferedWriter(new FileWriter(filename));
out.write(text);
out.close();
} catch (IOException e) {}
}

String ReadTextToFile(String filename, String text) throws FileNotFoundException
{
try {
BufferedReader rd = new BufferedReader(new FileReader(filename));
text=rd.readLine();
rd.close();
} catch (IOException e) {}
textToApplet=text;
return textToApplet;
}

String Collection (String filename) throws FileNotFoundException
{
Scanner file=new Scanner(new File(filename));
TreeSet<Integer> list=new TreeSet<Integer>();
while (file.hasNext()){
list.add(file.nextInt());
}
textToApplet=""+list;
return textToApplet;
}


}



заранее спасибо всем, кто поможет!

_________________
Rylov
http://loving-bitches.livejournal.com/
http://nasko-kammi.blogspot.com/



Партнер
 

Member
Статус: Не в сети
Регистрация: 01.08.2005
Откуда: Msk
up

_________________
Rylov
http://loving-bitches.livejournal.com/
http://nasko-kammi.blogspot.com/


 

Member
Статус: Не в сети
Регистрация: 09.01.2009
Откуда: Москва
Запиши код через этот сервис http://pastie.org/ , ибо не читабельно, а так шансов больше, что кто-то поможет.


Показать сообщения за:  Поле сортировки  
Начать новую тему Новая тема / Ответить на тему Ответить  Сообщений: 3 
-

Часовой пояс: UTC + 3 часа


Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 26


Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Перейти:  
Создано на основе phpBB® Forum Software © phpBB Group
Русская поддержка phpBB | Kolobok smiles © Aiwan