Hi i have a problem and i will ask for ADVICE.
I have this SWING code witch create one PANEL , MENU BAR , and fore RADIO BUTTON
I wont to create inernal panel and draw line like push buttons
For EXAMPLE Fush radio button and draw line fush oder button and draw treangle butt this is oder topic
I reade samting for JComponent
public void paintComponent(Graphics g) {
super.paintComponent(g);
//Here we draw a obgects
}
I add this fragment of cothe BUT i dont no hau to conect it with main program
I will be glad if same one just rade a little part of code in my code
AND WHEN I MAKE A PLOGRAM TO Shou component AND OBGECTS
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Grafic_function extends JPanel{
public JMenuBar create_m_b(){
JMenuBar osnovna = new JMenuBar();
JMenu nachalo = new JMenu("****");
JMenu sreda = new JMenu("****");
JMenu krai = new JMenu("****");
osnovna.add(nachalo);
osnovna.add(sreda);
osnovna.add(krai);
JMenuItem a =new JMenuItem("");
JMenuItem b =new JMenuItem("");
nachalo.add(a);
nachalo.add(b);
JMenuItem c =new JMenuItem("");
JMenuItem d=new JMenuItem("");
sreda.add(c);
sreda.add(d);
JMenuItem e=new JMenuItem("");
JMenuItem f=new JMenuItem("");
krai.add(e);
krai.add(f);
return osnovna;
}
public JPanel create_l_p() {
JPanel all = new JPanel();
JPanel r_button = new JPanel();
JRadioButton sin = new JRadioButton("SIN");
sin.setSelected(true);
sin.setSize(50,50);
sin.setLocation(10,10);
JRadioButton cos = new JRadioButton("COS");
cos.setSize(50,50);
cos.setLocation(10,20);
JRadioButton tg = new JRadioButton("TG");
tg.setSize(50,50);
tg.setLocation(10,30);
JRadioButton cotg = new JRadioButton("COTG");
cotg.setSize(50,50);
cotg.setLocation(10,40);
ButtonGroup p_all_b_g = new ButtonGroup();
p_all_b_g.add(sin);
p_all_b_g.add(cos);
p_all_b_g.add(tg);
p_all_b_g.add(cotg);
all.add(sin);
all.add(cos);
all.add(tg);
all.add(cotg);
return all;
}
*******************************************
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(10,20,30,40);
}
************************************************
private static void createAndShowGUI(){
JFrame frame = new JFrame("[=] Hello World [=]");
Grafic_function demo = new Grafic_function();
frame.setJMenuBar(demo.create_m_b());
frame.setContentPane(demo.create_l_p());
frame.setSize(400, 400);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}