leí esto, según hasta donde entendí sólo tienes que pasar un 1 como parámetro para que retorne true si es probable que el número sea primo y false si no es probable que lo sea, si el parámetro es -1 funciona de forma inversa.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menúimport java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.TextField;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.StyledDocument;
public class DraftGUI implements MouseListener {
private static final String IMAGE_URL = "http://images.paramountbusinessjets.com/space/spaceshuttle.jpg";
private JPanel jpPack;
private JPanel jpCards;
private JPanel jpInfo;
private JPanel jpChat;
private TextField tf;
private StyledDocument doc;
private JTextPane tp;
private JScrollPane sp;
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
public DraftGUI() throws MalformedURLException {
final JFrame frame = new JFrame("Draft");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// set the content pane, we'll add everything to it and then add it to the frame
JPanel contentPane = new JPanel();
contentPane.setLayout(new GridBagLayout());
// creates some panels with some default values for now
JPanel jpCards = new JPanel(new BorderLayout());
jpCards.setBackground(Color.BLUE);
JPanel jpInfo = new JPanel();
jpInfo.setBackground(Color.GREEN);
JPanel jpPack = new JPanel(new GridBagLayout());
jpPack.setBackground(Color.RED);
// grab some info to make the JTextPane and make it scroll
tf = new TextField();
doc = new DefaultStyledDocument();
tp = new JTextPane(doc);
tp.setEditable(false);
sp = new JScrollPane(tp);
// adding the quantities to the chat panel
JPanel jpChat = new JPanel();
jpChat.setLayout(new BorderLayout());
jpChat.add("North", tf);
jpChat.add("Center", sp);
// a new GridBagConstraints used to set the properties/location of the panels
GridBagConstraints c = new GridBagConstraints();
// adding some panels to the content pane
// set it to start from the top left of the quadrant if it's too small
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.fill = GridBagConstraints.BOTH; // set it to fill both vertically and horizontally
c.gridx = 0; // set it to quadrant x=0 and
c.gridy = 0; // set it to quadrant y=0
c.weightx = 0.7;
c.weighty = 0.3;
contentPane.add(jpCards, c);
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.3;
c.weighty = 0.3;
contentPane.add(jpInfo, c);
c.gridx = 0;
c.gridy = 1;
c.weightx = 0.7;
c.weighty = 0.7;
contentPane.add(jpPack, c);
c.gridx = 1;
c.gridy = 1;
c.weightx = 0.3;
c.weighty = 0.7;
contentPane.add(jpChat, c);
// set some necessary values
frame.setContentPane(contentPane);
frame.setLocationByPlatform(true);
// This code works for adding an Image
// need to learn how to specify a path not dependent on the specific users's machine
// this is not a high priority for now though
GridBagConstraints d = new GridBagConstraints();
d.weightx = 1.0;
d.weighty = 1.0;
d.fill = GridBagConstraints.BOTH;
d.gridx = 0;
d.gridy = 0;
ImageLabel imageLabel1 = new ImageLabel(new ImageIcon(new URL(IMAGE_URL)));
jpPack.add(imageLabel1, d);
ImageLabel imageLabel2 = new ImageLabel(new ImageIcon(new URL(IMAGE_URL)));
d.gridx++;
jpPack.add(imageLabel2, d);
ImageLabel imageLabel3 = new ImageLabel(new ImageIcon(new URL(IMAGE_URL)));
d.gridy++;
jpPack.add(imageLabel3, d);
imageLabel1.addMouseListener(this);
imageLabel2.addMouseListener(this);
imageLabel3.addMouseListener(this);
frame.pack();
// 223, 310 are the aspect values for a card image, width, height
// these need to be maintained as the GUI size changes
frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
new DraftGUI();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
});
}
public static class ImageLabel extends JPanel {
private static int counter = 1;
private ImageIcon icon;
private int id = counter++;
public ImageLabel(ImageIcon icon) {
super();
setOpaque(false);
this.icon = icon;
}
@Override
public Dimension getPreferredSize() {
return new Dimension(icon.getIconWidth(), icon.getIconHeight());
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
double zoom = Math.min((double) getWidth() / icon.getIconWidth(), (double) getHeight() / icon.getIconHeight());
int width = (int) (zoom * icon.getIconWidth());
int height = (int) (zoom * icon.getIconHeight());
g.drawImage(icon.getImage(), (getWidth() - width) / 2, (getHeight() - height) / 2, width, height, this);
g.setFont(g.getFont().deriveFont(36.0f));
g.drawString(String.valueOf(id), getWidth() / 2, getHeight() / 2);
}
}
}
class Suma{
private int num1;
private int num2;
public Suma(int num1,int num2){
this.num1 = num1;
this.num2 = num2;
}
public int resultado(){
return num1 + num2;
}
}
Suma mySuma = new Suma(2,2); //2 + 2
System.out.println(mySuma.resultado());//imprime 4
class AlgunaClase{
public static int variable;
}
int array[10] = {1, 2, 3, 4, 4, 7, 8, 9, 5, 4};
int i;
for(i =0; i<10;i++){
printf(" %p \n", &array[i]);
}
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import java.awt.event.*;
import java.awt.*;
import java.beans.PropertyVetoException;
public class UCIChess extends JFrame {
JDesktopPane jdpDesktop;
static int openFrameCount = 0;
MyInternalFrame myInternalFrame;
public UCIChess() {
super("JInternalFrame Usage Demo");
// Make the main window positioned as 50 pixels from each edge of the
// screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset, screenSize.width - inset * 2,
screenSize.height - inset * 2);
// Add a Window Exit Listener
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
addKeyListener( new KeyAdapter(){
public void keyPressed(KeyEvent e){
if( e.getKeyCode() == KeyEvent.VK_ENTER ){
try {
myInternalFrame.setClosed(true);
myInternalFrame.dispose();
} catch (PropertyVetoException ex) {
System.err.println("Closing Exception");
}
}
}
});
// Create and Set up the GUI.
jdpDesktop = new JDesktopPane();
// A specialized layered pane to be used with JInternalFrames
createFrame(); // Create first window
setContentPane(jdpDesktop);
setJMenuBar(createMenuBar());
// Make dragging faster by setting drag mode to Outline
jdpDesktop.putClientProperty("JDesktopPane.dragMode", "outline");
}
protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Frame");
menu.setMnemonic(KeyEvent.VK_N);
JMenuItem menuItem = new JMenuItem("New IFrame");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createFrame();
}
});
menu.add(menuItem);
menuBar.add(menu);
return menuBar;
}
protected void createFrame() {
myInternalFrame = new MyInternalFrame();
myInternalFrame.setVisible(true);
// Every JInternalFrame must be added to content pane using JDesktopPane
jdpDesktop.add(myInternalFrame);
try {
myInternalFrame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {
}
}
public static void main(String[] args) {
UCIChess frame = new UCIChess();
frame.setVisible(true);
}
class MyInternalFrame extends JInternalFrame {
static final int xPosition = 30, yPosition = 30;
public MyInternalFrame() {
super("IFrame #" + (++openFrameCount), true, // resizable
true, // closable
true, // maximizable
true);// iconifiable
setSize(300, 300);
// Set the window's location.
setLocation(xPosition * openFrameCount, yPosition
* openFrameCount);
}
}
}
try {
jInternalFrame.setClosed(true);
} catch (PropertyVetoException ex) {
System.err.println("Closing Exception");
}