用java做个下载器难不难?、
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用java做个下载器难不难?、相关的知识,希望对你有一定的参考价值。
快做项目了,也是我开始学习java的第一个项目,怎么做啊?用到那些知识都是??还望达人给说下,谢谢
不难,用swing做,写的比较完善就会占内存很大,我想下载器应该不是很专业的,支持断点吗?不过还是有些搞头。追问呵呵呵,行,我得努力,呵呵!
参考技术A 你好,请问高手如何跨过这个坎的,我现在也是做java的第一个项目,也是做个下载器,是从两台不同的FTP服务器下载文件,支持断点,还要比较下载速度,显示下载了多少等,高手,请教啊 参考技术B 学java第一个项目就是下载器?~··············你们老师蛮高看你们的昂····追问
此话何意??呵呵
追答这个···这个·········
···········开始学java不是叫你敲HAOLL WORED而是做下载器!···········
······················
之前我们已经学了java的高级特性,包括反射机制,AWT,Swing,输入和输出处理,多态,继承,封装,数据结构,还桥helloworld吗老大?呵呵
追答也许是你的项目让我误会了!·····你再看看你的题目·········
····················
JAVA用swing做个日历
JAVA作业,我比作业要求的多加了些功能,可以滚轮和键盘左右键翻页快捷键做的也许比较傻吧,监听到就直接doClick();沉迷JAVA,对于我这种以前只写过控制台程序的来说,图形界面真是打开了新世界
//MySwingCalendar.java
package test2;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.KeyEventPostProcessor;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Calendar;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.CompoundBorder;
public class MySwingCalendar extends JFrame
/**
*
*/
private static final long serialVersionUID = 1L;
private Calendar calendar;
private final static String week[]="日","一","二","三","四","五","六";
private JLabel dayLable[][]=new JLabel[6][7],monthLable;
private void initCalendar()
calendar=Calendar.getInstance();
calendar.set(Calendar.DATE,0);
private void initFrame()
setIconImage(new ImageIcon("icon\\\\Calendar.gif").getImage());
setSize(500, 300);
getContentPane().setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
addWindowListener(new WindowAdapter()
@Override
public void windowOpened(WindowEvent e)
requestFocus();
);
public MySwingCalendar()
super("Calendar");
initCalendar();
initFrame();
JPanel northPanel=new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton preMonth=new JButton("上月");
preMonth.addActionListener(new ActionListener()
@Override
public void actionPerformed(ActionEvent e)
calendarAdd(-1);
);
northPanel.add(preMonth);
JButton nextMonth=new JButton("下月");
nextMonth.addActionListener(new ActionListener()
@Override
public void actionPerformed(ActionEvent e)
calendarAdd(1);
);
northPanel.add(nextMonth);
getContentPane().add(northPanel,BorderLayout.NORTH);
JPanel centerPanel=new JPanel(new GridLayout(7, 7,1,1));
centerPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
for(String s:week)
JButton weekButton=new JButton(s);
weekButton.addActionListener(new ActionListener()
@Override
public void actionPerformed(ActionEvent e)
requestFocus();
);
centerPanel.add(weekButton);
for(int i=0;i<6;i++)
for(int j=0;j<7;j++)
JPanel tempJpanel=new JPanel();
dayLable[i][j]=new JLabel();
//dayLable[i][j].enableInputMethods(true);
dayLable[i][j].setHorizontalAlignment(JLabel.CENTER);
if(j%2==0)tempJpanel.setBackground(Color.white);
else tempJpanel.setBackground(Color.lightGray);
tempJpanel.add(dayLable[i][j]);
centerPanel.add(tempJpanel);
getContentPane().add(centerPanel, BorderLayout.CENTER);
JPanel southPanel=new JPanel(new FlowLayout(FlowLayout.CENTER));
monthLable=new JLabel();
southPanel.add(monthLable);
getContentPane().add(southPanel,BorderLayout.SOUTH);
updateCalendar();
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(new KeyEventPostProcessor()
private long lastLeftPress=0;
private long lastRightPress=0;
@Override
public boolean postProcessKeyEvent(KeyEvent e)
long currentTime=System.currentTimeMillis();
if(e.getID() == KeyEvent.KEY_PRESSED)
if (e.getKeyCode() == KeyEvent.VK_LEFT&¤tTime-lastLeftPress>100)
lastLeftPress = currentTime;
preMonth.requestFocus();
preMonth.doClick();
else if (e.getKeyCode() == KeyEvent.VK_RIGHT&¤tTime-lastRightPress>100)
lastRightPress = currentTime;
nextMonth.requestFocus();
nextMonth.doClick();
return false;
);
addMouseWheelListener(new MouseWheelListener()
private long lastMove=0;
@Override
public void mouseWheelMoved(MouseWheelEvent e)
int wheelRotation=e.getWheelRotation();
long currentTime=System.currentTimeMillis();
if(wheelRotation==-1&¤tTime-lastMove>70)
lastMove=currentTime;
preMonth.requestFocus();
preMonth.doClick();
else if(wheelRotation==1&¤tTime-lastMove>70)
lastMove=currentTime;
nextMonth.requestFocus();
nextMonth.doClick();
);
setVisible(true);
public String toString()
String s=calendar.get(Calendar.YEAR)+"年"+(calendar.get(Calendar.MONTH)+1)+"月\\n";
for(String i:week)
s+=" "+i;
s+="\\n";
int day=calendar.get(Calendar.DAY_OF_WEEK)%7;
for(int i=0;i<day;i++)s+=" ";
int maxDay=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for(int i=1;i<=maxDay;i++)
s+=String.format("%4d",i);
if(day==6)
s+="\\n";
day=0;
else day++;
return s;
private void updateCalendar()
int i=0,j=calendar.get(Calendar.DAY_OF_WEEK)%7;;
int maxDay=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
//System.out.println(this);
for(int k=0;k<j;k++)dayLable[0][k].setText("");
for(int k=1;k<=maxDay;k++)
dayLable[i][j].setText(Integer.toString(k));
if(j==6)
i++;
j=0;
else j++;
while(i<6)
dayLable[i][j].setText("");
if(j==6)
i++;
j=0;
else j++;
monthLable.setText("日历:"+calendar.get(Calendar.YEAR)+"年"+(calendar.get(Calendar.MONTH)+1)+"月");
public void calendarAdd(int delta)
calendar.add(Calendar.MONTH,delta);
updateCalendar();
public static void main(String args[])
new MySwingCalendar();
以上是关于用java做个下载器难不难?、的主要内容,如果未能解决你的问题,请参考以下文章