Last active
February 20, 2021 12:08
-
-
Save fernfern260244/37927ba7ba10a375c84406c22247e749 to your computer and use it in GitHub Desktop.
Task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
import java.awt.FlowLayout; | |
import java.awt.event.*; | |
class MyApp extends JFrame implements ActionListener{ | |
final JLabel resultLabel; | |
public MyApp(){ | |
setTitle("My Application"); | |
setSize(300,200); | |
setLocation(500,50); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setLayout(new FlowLayout()); | |
final JLabel label = new JLabel("Hello Mor Nor"); | |
getContentPane().add(label); | |
final JButton button= new JButton("Yas Flash?"); | |
getContentPane().add(button); | |
button.addActionListener(this); | |
resultLabel = new JLabel(""); | |
getContentPane().add(resultLabel); | |
} | |
public void actionPerformed(ActionEvent e){ | |
JButton button = (JButton) e.getSource(); | |
if(button.getActionCommand().equals("punch")){ | |
resultLabel.setText("Pernant!"); | |
}else{ | |
resultLabel.setText("What do you call a three humped camel?"); | |
} | |
} | |
public static void main(String[] args) { | |
MyApp app = new MyApp(); | |
app.setVisible(true); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
import java.awt.FlowLayout; | |
import java.awt.BorderLayout; | |
import java.awt.GridLayout; | |
import java.awt.event.*; | |
class Task6 extends JFrame implements ActionListener{ | |
final JTextField topField; | |
final JTextField top2Field; | |
final JTextField bottomField; | |
final JTextField bottom2Field; | |
final JLabel equalsLabel; | |
public Task6(){ | |
setTitle("Fraction Calculator"); | |
setSize(380,200); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setLayout(new BorderLayout()); | |
final JButton calcButton = new JButton("Calculate"); | |
getContentPane().add(calcButton,BorderLayout.PAGE_END); | |
final JPanel calcPanel = new JPanel(new FlowLayout()); | |
calcPanel.setLayout(new GridLayout(2,1,10,5)); | |
getContentPane().add(calcPanel,BorderLayout.CENTER); | |
topField = new JTextField("1 ",1); | |
calcPanel.add(topField); | |
top2Field = new JTextField("5 ",1); | |
calcPanel.add(top2Field); | |
final JLabel plusLabel = new JLabel("+"); | |
plusLabel.setFont(plusLabel.getFont().deriveFont(20.0f)); | |
calcPanel.add(plusLabel); | |
bottomField = new JTextField(" 8",1); | |
calcPanel.add(bottomField); | |
bottom2Field = new JTextField(" 3",1); | |
calcPanel.add(bottom2Field); | |
equalsLabel = new JLabel("= ?"); | |
equalsLabel.setFont(equalsLabel.getFont().deriveFont(50.0f)); | |
calcPanel.add(equalsLabel); | |
} | |
public void actionPerformed(ActionEvent e){ | |
JButton button = (JButton)e.getSource(); | |
int a = Integer.parseInt(topField.getText()); | |
int b = Integer.parseInt(top2Field.getText()); | |
int c = Integer.parseInt(bottomField.getText()); | |
int d = Integer.parseInt(bottom2Field.getText()); | |
int sum = (a/c ) + (b/d ); | |
equalsLabel.setText("="+sum); | |
} | |
public static void main(String[]args){ | |
Task6 app = new Task6(); | |
app.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment