Bom dia, eu nunca trabalhei com a classe swing so trabalho com a classe swt e gostaria de saber se alguem tem um tutorial para me passar bom e facil de swing, pois não achei o mesmo no topico de tutoriais do forum
achei esse tutorial mto complexo ahuahuaa sou uma mula =)
Bem galera eu consegui fazer tudo que eu queria, porem eu to criando o arquivo Jar e ele nao abri em meu computador o que deve ser alguem pode me ajudar?
[code]import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Swing extends JFrame {
private JPanel panel;
public Swing() {
setTitle("Leitor de Excel");
panel = new JPanel();
panel.setLayout(new BorderLayout());
JToolBar toolbar = new JToolBar();
toolbar.setFloatable(false);
final JTextArea area = new JTextArea();
add(area, BorderLayout.CENTER);
add(toolbar, BorderLayout.NORTH);
JToolBar vertical = new JToolBar(JToolBar.VERTICAL);
vertical.setFloatable(false);
vertical.setMargin(new Insets(10, 5, 5, 5));
ImageIcon select = new ImageIcon(getClass().getResource("computer.png"));
ImageIcon shapeed = new ImageIcon(getClass().getResource("printer.png"));
ImageIcon exit = new ImageIcon(getClass().getResource("exit.png"));
JButton bexit = new JButton(exit);
bexit.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
bexit.setBorder(new EmptyBorder(3 ,0, 3, 0));
JButton selectb = new JButton(select);
selectb.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileopen = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("*.*", "c:/");
fileopen.addChoosableFileFilter(filter);
//FileInputStream fi = null;
int ret = fileopen.showDialog(panel, "Open file");
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fileopen.getSelectedFile();
FileInputStream fi = null;
try {
fi = new FileInputStream(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Scanner scan = new Scanner(fi);
String readLine ="";
String conteudo ="";
while (scan.hasNext()) {
readLine = scan.next();
conteudo += readLine+ "\r\n";
}
String text = conteudo.toString();
area.setText(text);
}
}
});
selectb.setBorder(new EmptyBorder(3, 0, 3, 0));
JButton shapeedb = new JButton(shapeed);
shapeedb.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileopen = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter("*.txt", "c:/");
fileopen.addChoosableFileFilter(filter);
int ret = fileopen.showDialog(panel, "Save File");
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fileopen.getSelectedFile();
FileOutputStream fo =null;
try {
fo = new FileOutputStream(file, false);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
fo.write(area.getText().getBytes());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
shapeedb.setBorder(new EmptyBorder(3, 0, 3, 0));
vertical.add(selectb);
vertical.add(shapeedb);
vertical.add(bexit);
add(vertical, BorderLayout.WEST);
JLabel statusbar = new JLabel(" Statusbar");
statusbar.setPreferredSize(new Dimension(-1, 22));
statusbar.setBorder(LineBorder.createGrayLineBorder());
add(statusbar, BorderLayout.SOUTH);
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) {
Swing swing =new Swing();
}
}[/code]