initial commit
This commit is contained in:
commit
1f2a330e69
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
### IntelliJ IDEA ###
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/remedial_syahdan.iml" filepath="$PROJECT_DIR$/remedial_syahdan.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
11
remedial_syahdan.iml
Normal file
11
remedial_syahdan.iml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
100
src/Soal1_Calculator_SYAHDAN.java
Normal file
100
src/Soal1_Calculator_SYAHDAN.java
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class Soal1_Calculator_SYAHDAN extends JFrame implements ActionListener {
|
||||||
|
private JTextField bilangan1Field, bilangan2Field, hasilField;
|
||||||
|
private JButton tambahBtn, kurangBtn, kaliBtn, bagiBtn;
|
||||||
|
|
||||||
|
public Soal1_Calculator_SYAHDAN() {
|
||||||
|
setTitle("CALCULATOR");
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setSize(400, 200);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
initComponents();
|
||||||
|
layoutComponents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initComponents() {
|
||||||
|
bilangan1Field = new JTextField(15);
|
||||||
|
bilangan2Field = new JTextField(15);
|
||||||
|
hasilField = new JTextField(15);
|
||||||
|
hasilField.setEditable(false);
|
||||||
|
|
||||||
|
tambahBtn = new JButton("+");
|
||||||
|
kurangBtn = new JButton("-");
|
||||||
|
kaliBtn = new JButton("x");
|
||||||
|
bagiBtn = new JButton(":");
|
||||||
|
|
||||||
|
tambahBtn.addActionListener(this);
|
||||||
|
kurangBtn.addActionListener(this);
|
||||||
|
kaliBtn.addActionListener(this);
|
||||||
|
bagiBtn.addActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void layoutComponents() {
|
||||||
|
setLayout(new GridBagLayout());
|
||||||
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
gbc.insets = new Insets(5, 5, 5, 5);
|
||||||
|
|
||||||
|
gbc.gridx = 0; gbc.gridy = 0;
|
||||||
|
add(new JLabel("Bilangan1"), gbc);
|
||||||
|
gbc.gridx = 1; gbc.gridwidth = 3;
|
||||||
|
add(bilangan1Field, gbc);
|
||||||
|
|
||||||
|
gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 1;
|
||||||
|
add(new JLabel("Bilangan2"), gbc);
|
||||||
|
gbc.gridx = 1; gbc.gridwidth = 3;
|
||||||
|
add(bilangan2Field, gbc);
|
||||||
|
|
||||||
|
gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 1;
|
||||||
|
add(tambahBtn, gbc);
|
||||||
|
gbc.gridx = 1;
|
||||||
|
add(kurangBtn, gbc);
|
||||||
|
gbc.gridx = 2;
|
||||||
|
add(kaliBtn, gbc);
|
||||||
|
gbc.gridx = 3;
|
||||||
|
add(bagiBtn, gbc);
|
||||||
|
|
||||||
|
gbc.gridx = 0; gbc.gridy = 3;
|
||||||
|
add(new JLabel("Hasil"), gbc);
|
||||||
|
gbc.gridx = 1; gbc.gridwidth = 3;
|
||||||
|
add(hasilField, gbc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
double bil1 = Double.parseDouble(bilangan1Field.getText());
|
||||||
|
double bil2 = Double.parseDouble(bilangan2Field.getText());
|
||||||
|
double hasil = 0;
|
||||||
|
|
||||||
|
if (e.getSource() == tambahBtn) {
|
||||||
|
hasil = bil1 + bil2;
|
||||||
|
} else if (e.getSource() == kurangBtn) {
|
||||||
|
hasil = bil1 - bil2;
|
||||||
|
} else if (e.getSource() == kaliBtn) {
|
||||||
|
hasil = bil1 * bil2;
|
||||||
|
} else if (e.getSource() == bagiBtn) {
|
||||||
|
if (bil2 != 0) {
|
||||||
|
hasil = bil1 / bil2;
|
||||||
|
} else {
|
||||||
|
hasilField.setText("Error: Division by zero");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hasilField.setText(String.valueOf(hasil));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
hasilField.setText("Error: Invalid input");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
new Soal1_Calculator_SYAHDAN().setVisible(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
151
src/Soal2_Biodata_SYAHDAN.java
Normal file
151
src/Soal2_Biodata_SYAHDAN.java
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
public class Soal2_Biodata_SYAHDAN extends JFrame implements ActionListener {
|
||||||
|
private JTextField namaField, alamatField;
|
||||||
|
private JRadioButton lakiRadio, perempuanRadio;
|
||||||
|
private ButtonGroup genderGroup;
|
||||||
|
private JComboBox<String> agamaCombo;
|
||||||
|
private JTextArea outputArea;
|
||||||
|
private JButton simpanBtn, resetBtn;
|
||||||
|
private JLabel titleLabel; // Added title label
|
||||||
|
|
||||||
|
public Soal2_Biodata_SYAHDAN() {
|
||||||
|
setTitle("BIODATA");
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setSize(400, 500);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
initComponents();
|
||||||
|
layoutComponents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initComponents() {
|
||||||
|
// Initialize title label
|
||||||
|
titleLabel = new JLabel("BIODATA", JLabel.CENTER);
|
||||||
|
titleLabel.setFont(new Font("Arial", Font.BOLD, 28));
|
||||||
|
titleLabel.setForeground(new Color(0, 100, 200));
|
||||||
|
|
||||||
|
namaField = new JTextField(20);
|
||||||
|
alamatField = new JTextField(20);
|
||||||
|
|
||||||
|
lakiRadio = new JRadioButton("Laki-laki");
|
||||||
|
perempuanRadio = new JRadioButton("Perempuan");
|
||||||
|
genderGroup = new ButtonGroup();
|
||||||
|
genderGroup.add(lakiRadio);
|
||||||
|
genderGroup.add(perempuanRadio);
|
||||||
|
|
||||||
|
String[] agamaList = {"Islam", "Kristen", "Katolik", "Hindu", "Buddha", "Konghucu"};
|
||||||
|
agamaCombo = new JComboBox<>(agamaList);
|
||||||
|
|
||||||
|
outputArea = new JTextArea(8, 30);
|
||||||
|
outputArea.setEditable(false);
|
||||||
|
outputArea.setBorder(BorderFactory.createLoweredBevelBorder());
|
||||||
|
|
||||||
|
simpanBtn = new JButton("Simpan");
|
||||||
|
resetBtn = new JButton("Reset");
|
||||||
|
|
||||||
|
simpanBtn.addActionListener(this);
|
||||||
|
resetBtn.addActionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void layoutComponents() {
|
||||||
|
setLayout(new GridBagLayout());
|
||||||
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
gbc.insets = new Insets(5, 5, 5, 5);
|
||||||
|
gbc.anchor = GridBagConstraints.WEST;
|
||||||
|
|
||||||
|
// Title Label
|
||||||
|
gbc.gridx = 0; gbc.gridy = 0;
|
||||||
|
gbc.gridwidth = 2;
|
||||||
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc.anchor = GridBagConstraints.CENTER;
|
||||||
|
add(titleLabel, gbc);
|
||||||
|
|
||||||
|
// Reset for other components
|
||||||
|
gbc.gridwidth = 1;
|
||||||
|
gbc.fill = GridBagConstraints.NONE;
|
||||||
|
gbc.anchor = GridBagConstraints.WEST;
|
||||||
|
|
||||||
|
// Nama
|
||||||
|
gbc.gridx = 0; gbc.gridy = 1;
|
||||||
|
add(new JLabel("Nama"), gbc);
|
||||||
|
gbc.gridx = 1;
|
||||||
|
add(namaField, gbc);
|
||||||
|
|
||||||
|
// Alamat
|
||||||
|
gbc.gridx = 0; gbc.gridy = 2;
|
||||||
|
add(new JLabel("Alamat"), gbc);
|
||||||
|
gbc.gridx = 1;
|
||||||
|
add(alamatField, gbc);
|
||||||
|
|
||||||
|
// Gender
|
||||||
|
gbc.gridx = 0; gbc.gridy = 3;
|
||||||
|
add(new JLabel("Gender"), gbc);
|
||||||
|
gbc.gridx = 1;
|
||||||
|
JPanel genderPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||||
|
genderPanel.add(lakiRadio);
|
||||||
|
genderPanel.add(perempuanRadio);
|
||||||
|
add(genderPanel, gbc);
|
||||||
|
|
||||||
|
// Agama
|
||||||
|
gbc.gridx = 0; gbc.gridy = 4;
|
||||||
|
add(new JLabel("Agama"), gbc);
|
||||||
|
gbc.gridx = 1;
|
||||||
|
add(agamaCombo, gbc);
|
||||||
|
|
||||||
|
// Output Area
|
||||||
|
gbc.gridx = 0; gbc.gridy = 5;
|
||||||
|
gbc.gridwidth = 2;
|
||||||
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
|
add(new JScrollPane(outputArea), gbc);
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
gbc.gridx = 0; gbc.gridy = 6;
|
||||||
|
gbc.gridwidth = 2;
|
||||||
|
gbc.fill = GridBagConstraints.NONE;
|
||||||
|
JPanel buttonPanel = new JPanel(new FlowLayout());
|
||||||
|
buttonPanel.add(simpanBtn);
|
||||||
|
buttonPanel.add(resetBtn);
|
||||||
|
add(buttonPanel, gbc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (e.getSource() == simpanBtn) {
|
||||||
|
String nama = namaField.getText();
|
||||||
|
String alamat = alamatField.getText();
|
||||||
|
String gender = "";
|
||||||
|
|
||||||
|
if (lakiRadio.isSelected()) {
|
||||||
|
gender = "Laki-laki";
|
||||||
|
} else if (perempuanRadio.isSelected()) {
|
||||||
|
gender = "Perempuan";
|
||||||
|
}
|
||||||
|
|
||||||
|
String agama = (String) agamaCombo.getSelectedItem();
|
||||||
|
|
||||||
|
String output = "Nama\t\t:" + nama + "\n" +
|
||||||
|
"Alamat\t\t:" + alamat + "\n" +
|
||||||
|
"Gender\t\t:" + gender + "\n" +
|
||||||
|
"Agama\t\t:" + agama;
|
||||||
|
|
||||||
|
outputArea.setText(output);
|
||||||
|
|
||||||
|
} else if (e.getSource() == resetBtn) {
|
||||||
|
namaField.setText("");
|
||||||
|
alamatField.setText("");
|
||||||
|
genderGroup.clearSelection();
|
||||||
|
agamaCombo.setSelectedIndex(0);
|
||||||
|
outputArea.setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
new Soal2_Biodata_SYAHDAN().setVisible(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user