Thread: java
View Single Post
blue sky

 
Member Since: Mar 20, 2013
Posts: 3
blue sky is on a distinguished road

blue sky is offline
snow leopard is running:

Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-10M4203)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)

mountain lion is running:

Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-11M4203)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)

here is the code:

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

public class Grade extends JFrame
{
static JMenu myMenu;
static TabOne tabOne;
static TabTwo tabTwo;
static TabTre tabTre;

static int SW = 800;
static int SH = 550;

static JDesktopPane desk = new JDesktopPane();

static JTabbedPane jtp = new JTabbedPane();
static JMenuBar jmb = new JMenuBar();
static JPanel panel = new JPanel();;

public static void main(String[] args)
{
final Grade f = new Grade();

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

int w = (d.width-SW)/2;
int h = (d.height-SH)/2;
f.setBounds(w, h, SW,SH);

f.setVisible(true);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}

public Grade()
{
super();

this.setTitle("java");

mkGui();

panel.setLayout(new BorderLayout());

setContentPane(desk);
desk.addComponentListener(new ComponentAdapter()
{
public void componentResized(ComponentEvent e)
{
Dimension d = desk.getSize();
panel.setBounds(0,0, d.width, d.height);
panel.validate();
}
});
desk.add(panel);
}

public void mkGui()
{
Thread w = new Thread()
{
public void run()
{
mkMenu();
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
mkTab();
mkTabListener();
}
});
}
};
w.start();
try
{
w.join();
}
catch (InterruptedException e) {}
}

public void mkMenu()
{
JMenuItem myItem = new JMenuItem("Essentials");
myItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});

myMenu = new JMenu("Input");

jmb.add(myMenu);
setJMenuBar(jmb);
}

public void mkTab()
{
jtp.addTab("disable extra", null, tabOne = new TabOne(), "");
jtp.addTab("enable extra", null, tabTwo = new TabTwo(), "");
jtp.addTab("extra", null, tabTre = new TabTre(), "");

jtp.setEnabledAt(2, false);

jtp.setTabPlacement(SwingConstants.TOP);
jtp.setBackground(Color.white);
panel.add(jtp);
}

public void mkTabListener()
{
jtp.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
tabHit();
}
});
}

public void tabHit()
{
if (jtp.getTitleAt(jtp.getSelectedIndex()).equals("di sable extra"))
{
jtp.setEnabledAt(2, false);
}
else
if (jtp.getTitleAt(jtp.getSelectedIndex()).equals("en able extra"))
{
jtp.setEnabledAt(2, true);
}
else
if (jtp.getTitleAt(jtp.getSelectedIndex()).equals("ex tra"))
{
}
}

public class TabOne extends JPanel
{
public TabOne()
{
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(new JLabel(""), BorderLayout.CENTER);

this.setLayout(new BorderLayout());
this.add(p1, BorderLayout.CENTER);
}
}

public class TabTwo extends JPanel
{
public TabTwo()
{
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(new JLabel(""), BorderLayout.CENTER);

this.setLayout(new BorderLayout());
this.add(p1, BorderLayout.CENTER);
}
}

public class TabTre extends JPanel
{
public TabTre()
{
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(new JLabel(""), BorderLayout.CENTER);

this.setLayout(new BorderLayout());
this.add(p1, BorderLayout.CENTER);
}
}
}
QUOTE Thanks