Showing posts with label تکه کد. Show all posts
Showing posts with label تکه کد. Show all posts

Tuesday, April 28, 2009

فوکوس

برای بردن فوکوس بر روری یک شی می تونید از از دستور زیر استفاده کنید :
نام شی.requestFocusInWindow();
در مثال زیر بعد کلیک بر روی دکمه bold ,فوکوس به jtextfield منتقل می شود :

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


public class Focus extends JFrame implements ActionListener {
private JButton btnBold;
private JTextField txtArea;
public Focus() {
init();
panel();
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
new Focus();
}
public void init() {
btnBold = new JButton("Blod");
btnBold.addActionListener(this);
txtArea = new JTextField(40);
txtArea.addActionListener(this);
}
public void panel() {
setLayout(new GridLayout(2,2));
add(txtArea);
add(btnBold);
}
@Override
public void actionPerformed(ActionEvent e)
{
if (btnBold == e.getSource()) {
Font b = new Font("Sans Serif", Font.BOLD, 16);
txtArea.setFont(b);
txtArea.requestFocusInWindow();
}
}
}
به نقل از :java_nith

Maximize کردن Jframe و از بین بردن border

Maximize کردن jframe و از بین بردن border فریم

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


public class FullScreenJFrame extends JFrame {

public FullScreenJFrame(String title) {
super(title);

this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

setUndecorated(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(0, 0, screenSize.width, screenSize.height);
getContentPane().add(new JLabel("A JFrame Based Kiosk"), BorderLayout.NORTH);
JButton closeButton = new JButton("Close");
closeButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {
System.out.println("Close button Pressed");
FullScreenJFrame.this.setVisible(false);
System.exit(0);
}
});
getContentPane().add(closeButton, BorderLayout.CENTER);
}

public static void main(String[] args) {
FullScreenJFrame frame = new FullScreenJFrame("");
frame.setVisible(true);
}
}
به نقل از : saeedIRHA