|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0 
|
Quote:
Originally Posted by reggaeton_king
I don't think decompilers translate "exactly" what someone wrote or am I wrong?
|
Well as a test I used a ".java" file and a ".class" file to see the difference between them. First off, it seems like the comments are stripped out of the code when decompiled. Second, functions are not in the same order as they were in the original code. **BUT** You can basically get back everything else you've written (with a different variation to how you accomplished the design of your program).
NOTE: USED "CAVAJ Java Decompiler"
ORIGINAL SOURCE: ".java" file
/**
* Contains radio boxes, labels, textBoxes, comboBox, checkBoxes, textFields
and actionListener. Done by Placing all components on a JPanel. Once done, places all
JPanels on GridLayout().
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Survey extends JFrame implements ActionListener
{
JScrollPane scrFeedBack; // scroll bar for txtFeedBack
JTextArea txtFeedBack; // text area for comments
public Survey()
{
super("Health Awareness Survey");
//Place first Question
JLabel lblSleep = new JLabel("3: On average how many hours of sleep do you get per night?");
JComboBox cmbSleep = new JComboBox();
cmbSleep.addItem("3-5 hours");
cmbSleep.addItem("5-6 hours");
cmbSleep.addItem("6-7 hours");
cmbSleep.addItem("7-8 hours");
cmbSleep.addItem("> 9 hours");
cmbSleep.setEditable(false); // so user can't mess with the data
cmbSleep.setMaximumRowCount(3);
//adds the basic label + the comboBox
FlowLayout flowSleep = new FlowLayout(FlowLayout.LEFT,0,0);
JPanel pnlSleep = new JPanel(flowSleep);
pnlSleep.add(lblSleep);
pnlSleep.add(cmbSleep);
// Second Question
JLabel lblFood = new JLabel ("4. How many items of junk food do you consume per week?");
JRadioButton opt0Items = new JRadioButton("0-5 Items");
JRadioButton opt5Items = new JRadioButton("5-10 Items");
JRadioButton opt10Items = new JRadioButton("10-15 Items");
// create a button group for the radio buttons (so that you can only select 1 at a time)
ButtonGroup grpItems = new ButtonGroup();
grpItems.add(opt0Items);
grpItems.add(opt5Items);
grpItems.add(opt10Items);
FlowLayout flowItems = new FlowLayout(FlowLayout.LEFT, 1,0); // adds to the visuals ;)
JPanel pnlItems = new JPanel(flowItems);
pnlItems.add(lblFood); // adding labels and optionBoxes to the Panel
pnlItems.add(opt0Items);
pnlItems.add(opt5Items);
pnlItems.add(opt10Items);
//Third Question
JCheckBox chkHealthy = new JCheckBox("2. Is the majority of food you eat healthy?", false);
JLabel lblStatus = new JLabel("5: At what time(s) of the days do you brush your teeth?");
JCheckBox chkMorning = new JCheckBox ("1. Morning "); // creats a CheckBox
JCheckBox chkLunch = new JCheckBox ("2. Lunch "); // that isn't a family with the
JCheckBox chkNight = new JCheckBox ("3. Night"); // other ones
// panel that will hold all the CheckBox components + the label
FlowLayout flowTeeth = new FlowLayout(FlowLayout.LEFT, 1,0);
JPanel pnlTeeth = new JPanel(flowItems);
pnlTeeth.add(lblStatus);
pnlTeeth.add(chkMorning);
pnlTeeth.add(chkLunch);
pnlTeeth.add(chkNight);
//Fourth Question
JLabel lblFav = new JLabel("1. What is your favorite food?");
JTextField txtFav = new JTextField(25);
txtFav.setToolTipText("Enter your favorite food");
//adds fourth question to the JPanel for later use
FlowLayout flowFood = new FlowLayout(FlowLayout.LEFT, 1,0);
JPanel pnlFav = new JPanel(flowFood);
pnlFav.add(lblFav);
pnlFav.add(txtFav);
JLabel lblDrinks = new JLabel ("6. What do you usually drink in the morning?");
String[] strDrink = {"Orange", "Juice", "Milk", "Coffee", "Tea", "Other", "can't remember"};
JList drink = new JList(strDrink);
// set how much space the list takes up
drink.setVisibleRowCount(2);
JScrollPane scrDrinks = new JScrollPane(drink, ScrollPaneConstants.
VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
// Label + box goes in the panel
FlowLayout flowDrinks = new FlowLayout(FlowLayout.LEFT, 1,0);
JPanel pnlDrinks = new JPanel(flowDrinks);
pnlDrinks.add(lblDrinks);
pnlDrinks.add(scrDrinks);
// ALL THE COMPONENTS ABOVE, get added to the main layout here
JPanel pnlFields = new JPanel(new GridLayout(5, 1));
pnlFields.add(pnlFav);
pnlFields.add(pnlSleep);
pnlFields.add(pnlItems);
pnlFields.add(pnlTeeth);
pnlFields.add(pnlDrinks);
pnlFav.add(chkHealthy);
//Comment Box + Button
JLabel lblFeedBack = new JLabel("Before you submit form, please take a moment to enter any feedback you'd like to give us");
// uses HTML code to produce a line ;)
lblFeedBack.setText("<html><hr>Before you submit form, please take<br> a moment to to enter any feedback you <br> would like to give us</html>");
lblFeedBack.setSize(10, 4);
txtFeedBack = new JTextArea(4, 30); // creating a textbox
txtFeedBack.setLineWrap(true); // so that the text goes to next line when full
txtFeedBack.setWrapStyleWord(true);
txtFeedBack.setToolTipText("Enter your (Questions/Problems) here");
scrFeedBack = new JScrollPane(txtFeedBack, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
JPanel pnlAddress = new JPanel(new BorderLayout());
pnlAddress.add(lblFeedBack, BorderLayout.CENTER);
JButton cmdSubmit = new JButton("Submit");
JButton cmdReset = new JButton("Reset");
JButton cmdExit = new JButton("Exit");
cmdSubmit.setMnemonic(KeyEvent.VK_G);// G instead of S, incase people think 'S = save'
cmdSubmit.setToolTipText("Click here to submit form");
cmdReset.setMnemonic(KeyEvent.VK_R); // hotkey for 'r'
cmdReset.setToolTipText("Click here to reset form");
cmdExit.setMnemonic(KeyEvent.VK_E); // adds hotkeys 'e'
cmdExit.setToolTipText("Click here to exit the program.");
JPanel pnlButtons = new JPanel(new GridLayout(1,0));
pnlButtons.add(cmdSubmit);
pnlButtons.add(cmdReset);
pnlButtons.add(cmdExit);
JPanel pnlFeedBack = new JPanel(new BorderLayout());
pnlFeedBack.add(pnlButtons, BorderLayout.SOUTH);
pnlFeedBack.add(scrFeedBack, BorderLayout.CENTER);
pnlFeedBack.add(lblFeedBack, BorderLayout.NORTH);
Container pane = this.getContentPane();
pane.setLayout(new BorderLayout());
pane.add(pnlFeedBack, BorderLayout.SOUTH);
pane.add(pnlFields, BorderLayout.CENTER);
// Action listeners
cmdSubmit.addActionListener(this);
cmdExit.addActionListener(this);
cmdReset.addActionListener(this);
//final configurations
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setSize (350, 500);
}
/*
* Performs tasks based on buttons pressed
*/
/**
* The Action Listener, takes in an ActionEvent.
*/
public void actionPerformed(ActionEvent evt)
{
Object source = evt.getSource();
}
FROM ".class" file decompiled
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import javax.swing.*;
public class Survey extends JFrame
implements ActionListener
{
JScrollPane scrFeedBack;
JTextArea txtFeedBack;
public void actionPerformed(ActionEvent actionevent)
{
Object obj = actionevent.getSource();
}
public Survey()
{
super("Health Awareness Survey");
JLabel jlabel = new JLabel("3: On average how many hours of sleep do you get per night?");
JComboBox jcombobox = new JComboBox();
jcombobox.addItem("3-5 hours");
jcombobox.addItem("5-6 hours");
jcombobox.addItem("6-7 hours");
jcombobox.addItem("7-8 hours");
jcombobox.addItem("> 9 hours");
jcombobox.setEditable(false);
jcombobox.setMaximumRowCount(3);
FlowLayout flowlayout = new FlowLayout(0, 0, 0);
JPanel jpanel = new JPanel(flowlayout);
jpanel.add(jlabel);
jpanel.add(jcombobox);
JLabel jlabel1 = new JLabel("4. How many items of junk food do you consume per week?");
JRadioButton jradiobutton = new JRadioButton("0-5 Items");
JRadioButton jradiobutton1 = new JRadioButton("5-10 Items");
JRadioButton jradiobutton2 = new JRadioButton("10-15 Items");
ButtonGroup buttongroup = new ButtonGroup();
buttongroup.add(jradiobutton);
buttongroup.add(jradiobutton1);
buttongroup.add(jradiobutton2);
FlowLayout flowlayout1 = new FlowLayout(0, 1, 0);
JPanel jpanel1 = new JPanel(flowlayout1);
jpanel1.add(jlabel1);
jpanel1.add(jradiobutton);
jpanel1.add(jradiobutton1);
jpanel1.add(jradiobutton2);
JCheckBox jcheckbox = new JCheckBox("2. Is the majority of food you eat healthy?", false);
JLabel jlabel2 = new JLabel("5: At what time(s) of the days do you brush your teeth?");
JCheckBox jcheckbox1 = new JCheckBox("1. Morning ");
JCheckBox jcheckbox2 = new JCheckBox("2. Lunch ");
JCheckBox jcheckbox3 = new JCheckBox("3. Night");
FlowLayout flowlayout2 = new FlowLayout(0, 1, 0);
JPanel jpanel2 = new JPanel(flowlayout1);
jpanel2.add(jlabel2);
jpanel2.add(jcheckbox1);
jpanel2.add(jcheckbox2);
jpanel2.add(jcheckbox3);
JLabel jlabel3 = new JLabel("1. What is your favorite food?");
JTextField jtextfield = new JTextField(25);
jtextfield.setToolTipText("Enter your favorite food");
FlowLayout flowlayout3 = new FlowLayout(0, 1, 0);
JPanel jpanel3 = new JPanel(flowlayout3);
jpanel3.add(jlabel3);
jpanel3.add(jtextfield);
JLabel jlabel4 = new JLabel("6. What do you usually drink in the morning?");
String as[] = {
"Orange", "Juice", "Milk", "Coffee", "Tea", "Other", "can't remember"
};
JList jlist = new JList(as);
jlist.setVisibleRowCount(2);
JScrollPane jscrollpane = new JScrollPane(jlist, 20, 31);
FlowLayout flowlayout4 = new FlowLayout(0, 1, 0);
JPanel jpanel4 = new JPanel(flowlayout4);
jpanel4.add(jlabel4);
jpanel4.add(jscrollpane);
JPanel jpanel5 = new JPanel(new GridLayout(5, 1));
jpanel5.add(jpanel3);
jpanel5.add(jpanel);
jpanel5.add(jpanel1);
jpanel5.add(jpanel2);
jpanel5.add(jpanel4);
jpanel3.add(jcheckbox);
JLabel jlabel5 = new JLabel("Before you submit form, please take a moment to enter any feedback you'd like to" +
" give us"
);
jlabel5.setText("<html><hr>Before you submit form, please take<br> a moment to to enter any feedb" +
"ack you <br> would like to give us</html>"
);
jlabel5.setSize(10, 4);
txtFeedBack = new JTextArea(4, 30);
txtFeedBack.setLineWrap(true);
txtFeedBack.setWrapStyleWord(true);
txtFeedBack.setToolTipText("Enter your (Questions/Problems) here");
scrFeedBack = new JScrollPane(txtFeedBack, 22, 31);
JPanel jpanel6 = new JPanel(new BorderLayout());
jpanel6.add(jlabel5, "Center");
JButton jbutton = new JButton("Submit");
JButton jbutton1 = new JButton("Reset");
JButton jbutton2 = new JButton("Exit");
jbutton.setMnemonic(71);
jbutton.setToolTipText("Click here to submit form");
jbutton1.setMnemonic(82);
jbutton1.setToolTipText("Click here to reset form");
jbutton2.setMnemonic(69);
jbutton2.setToolTipText("Click here to exit the program.");
JPanel jpanel7 = new JPanel(new GridLayout(1, 0));
jpanel7.add(jbutton);
jpanel7.add(jbutton1);
jpanel7.add(jbutton2);
JPanel jpanel8 = new JPanel(new BorderLayout());
jpanel8.add(jpanel7, "South");
jpanel8.add(scrFeedBack, "Center");
jpanel8.add(jlabel5, "North");
Container container = getContentPane();
container.setLayout(new BorderLayout());
container.add(jpanel8, "South");
container.add(jpanel5, "Center");
jbutton.addActionListener(this);
jbutton2.addActionListener(this);
jbutton1.addActionListener(this);
pack();
setDefaultCloseOperation(3);
setVisible(true);
setSize(350, 500);
}
}
__________________
Death smiles at us all. All a man can do is smile back.
|