Tugas 2 java terdiri atas 2 file
atau download di sini.
1. file internal
yang berisi :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class internal extends JInternalFrame{
//private JInternalFrame saya = new JInternalFrame ();
private JLabel label1 = new JLabel("massa (m) ="),
label2 = new JLabel("percepatan (a)="),
label3 = new JLabel("gaya (F) =");
private JTextField txt1 = new JTextField(),
txt2 = new JTextField(),
txt3 = new JTextField();
private JLabel gambar = new JLabel (new ImageIcon("adhi2.jpg"));
private JButton btnCari = new JButton("hitung");
public internal(){
super("GAYA",false,true,true,true);
getContentPane().setLayout(null);
label1.setBounds(30,20,100,20);
label2.setBounds(30,60,100,20);
label3.setBounds(30,100,100,20);
gambar.setBounds(0,0,250,250);
txt1.setBounds(130,20,100,20);
txt2.setBounds(130,60,100,20);
txt3.setBounds(130,100,100,20);
btnCari.setBounds(130,140,100,20);
getContentPane().add(label1);
getContentPane().add(label2);
getContentPane().add(label3);
getContentPane().add(txt1);
getContentPane().add(txt2);
getContentPane().add(txt3);
getContentPane().add(btnCari);
getContentPane().add(gambar);
btnCari.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int Hasil = Integer.parseInt(txt1.getText()) * Integer.parseInt(txt2.getText());
txt3.setText(Integer.toString(Hasil));
}
});
setVisible(true);
setSize(280,280);
}
}
untuk file ke dua ber judul RmsAdhi
yang isi nya :
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class RmsAdhi{
private JDesktopPane baru = new JDesktopPane ();
private JFrame adhi = new JFrame("aplikasi menghitung Gaya");
private JPanel panel1 = new JPanel();
private JMenuBar cahya = new JMenuBar ();
private JMenu file = new JMenu ("file"),
edit = new JMenu ("edit"),
search = new JMenu ("search"),
view = new JMenu ("view");
private JMenuItem filenew = new JMenuItem ("new"),
fileopen = new JMenuItem ("open"),
filesave = new JMenuItem ("save"),
filesaveas = new JMenuItem ("exit"),
editundo = new JMenuItem ("undo"),
editcopy = new JMenuItem ("copy"),
editpaste= new JMenuItem ("paste"),
searchfind = new JMenuItem ("find"),
searchreplace = new JMenuItem ("replace"),
searchgoto = new JMenuItem ("go to"),
viewshow = new JMenuItem("show"),
viewwrap = new JMenuItem ("wrap"),
viewzoomin= new JMenuItem ("zoom in ");
private JToolBar tool = new JToolBar ();
private JButton btnnew = new JButton (new ImageIcon("adhie.jpg"));
//private JLabel gambar = new JLabel (new ImageIcon("g.jpg"));
public RmsAdhi (){
file.add(filenew);
file.add(fileopen);
file.addSeparator();
file.add(filesave);
file.add(filesaveas);
edit.add(editundo);
edit.add(editcopy);
edit.addSeparator();
edit.add(editpaste);
search.add(searchfind);
search.add(searchreplace);
search.add(searchgoto);
view.add(viewshow);
view.add(viewwrap);
view.add(viewzoomin);
cahya.add(file);
cahya.add(edit);
cahya.add(search);
cahya.add(view);
adhi.setJMenuBar(cahya);
ActionListener mulai = new ActionListener(){
public void actionPerformed(ActionEvent e){
internal x = new internal ();
baru.add(x);
x.setVisible(true);
}
};
btnnew.addActionListener(mulai);
tool.add(btnnew);
baru.setBackground(Color.blue);
adhi.getContentPane().add(tool, BorderLayout.NORTH);
adhi.getContentPane().add(baru, BorderLayout.CENTER);
//afdal.getContentPane().add(gambar);
adhi.setVisible(true);
adhi.setSize (800,500);
adhi.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String[] args ){
new RmsAdhi ();
}
}
atau download di sini.
Tidak ada komentar:
Posting Komentar